我想使用hudson的管道插件获取内联管道脚本中的当前时间戳。用于设置生成显示名称。
使用的内联groovy脚本:
def jobName = env.JOB_NAME + "_" + new Date()
currentBuild.displayName = "$jobName"
node {
echo "job name $jobName"
}
控制台上的错误:
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException:
Scripts not permitted to use new java.util.Date
发布于 2017-04-13 18:18:55
你也可以使用这个,我需要这个,所以:
echo "TimeStamp: ${currentBuild.startTimeInMillis}"
echo "TimeStamp: ${Util.getTimeSpanString(System.currentTimeMillis())}"
发布于 2018-06-27 04:09:21
只需格式化Date
对象:
stage('Foo') {
steps {
script {
def now = new Date()
println now.format("yyMMdd.HHmm", TimeZone.getTimeZone('UTC'))
}
}
}
发布于 2019-03-19 18:02:15
您还可以通过在字符串上下文中使用LocalDateTime
或LocalDate
来避免脚本审批。这些将为您提供ISO 8601默认值:
script {
DATE_TAG = java.time.LocalDate.now()
DATETIME_TAG = java.time.LocalDateTime.now()
}
sh "echo ${DATETIME_TAG}"
https://stackoverflow.com/questions/40261710
复制相似问题