使用 hudson 的管道插件获取内联管道脚本中的当前时间戳 [英] Getting current timestamp in inline pipeline script using pipeline plugin of hudson

查看:25
本文介绍了使用 hudson 的管道插件获取内联管道脚本中的当前时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 hudson 的管道插件获取内联管道脚本中的当前时间戳.用于设置构建显示名称.

I want to get Getting current timestamp in inline pipeline script using pipeline plugin of hudson. For setting up build display name.

使用的内联 groovy 脚本:

Inline groovy script used:

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

推荐答案

Jenkins 脚本在沙箱中运行,默认情况下 Groovy 脚本没有某些操作的权限.

Jenkins scripts are running in a sandbox, by default the Groovy script doesn't have permissions for some operations.

当您在没有权限的情况下执行操作时,会抛出 RejectAccessException.所以你必须执行你的脚本,然后在抛出异常时转到:

When you perform an operation without permissions the RejectAccessException is thrown. So you've to execute your script, and then when the exception is thrown go to:

http://yourHost/jenkins/scriptApproval/

并批准必要的权限:

这篇关于使用 hudson 的管道插件获取内联管道脚本中的当前时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆