how to create a directory with datestamp as its filename in jenkins pipeline?

922 Views Asked by At
bat 'set OutputFolderName=%date:~12,2%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%%time:~6,2%'
bat 'mkdir %OutputFolderName%'

These two commands should give the correct output but they aren't working. This is the error I got:

1

There are 1 best solutions below

3
Siddharth Kaul On BEST ANSWER

Try multiline bat command as follows:

bat """
    set OutputFolderName=%date:~12,2%%date:~4,2%%date:~7,2%_%time:~0,2%%time:~3,2%%time:~6,2%
    mkdir %OutputFolderName%
"""

Edit: Updated with snapshots

Have a look at my pipeline snapshot here: Pipeline Snapshot

Pipeline Console Output Pipeline Console Output

Creates a folder something like this:

Workspace Snapshot