jenkinstimestampjenkins-pipelinemkdirsdatestamp

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


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:


Solution

  • 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