Getting current timestamp in an inline script pipeline using the hudson plugin pipeline

I want to get the current timestamp in an inline script pipeline using the hudson pipeline plugin. To customize the display name of the assembly.

Inline groovy script used:

def jobName = env.JOB_NAME + "_" + new Date()
currentBuild.displayName = "$jobName"
node {
   echo "job name $jobName"
}

Error on console:

org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: 
  Scripts not permitted to use new java.util.Date
+4
source share
2 answers

Jenkins scripts run in the sandbox, by default the Groovy script does not have permissions for some operations.

When performing an operation without permissions issued RejectAccessException. So you have to execute your script, and then when the exception is thrown, go to:

http://yourHost/jenkins/scriptApproval/

And confirm the required permission:

enter image description here

+4

, ms, :

echo "TimeStamp: ${currentBuild.startTimeInMillis}"

echo "TimeStamp: ${Util.getTimeSpanString(System.currentTimeMillis()}"
+6

Source: https://habr.com/ru/post/1658928/


All Articles