Search code examples
jenkinsjenkins-workflow

Getting date and time in a Workflow Script


From within a workflow script we are using a tool that puts a timestamp into the path, we therefore need to be able to get the current date and time from within the groovy script.

Is there a step or some compatible Java we can use to do this?


Solution

  • import java.text.SimpleDateFormat
    {
       ...  
       def dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm");
       def date = new Date();
    
       println(dateFormat.format(date));
       ...
    }