在 Jenkins Promoted 构建插件脚本中访问 BUILD_NUMBER

Access BUILD_NUMBER in Jenkins Promoted build plugin scripts

我正在使用 Promoted Build 插件。并使用一些自定义 groovy 脚本来验证构建!我想从 groovy 脚本访问 BUILD_NUMBER 的值。谁能建议我如何实现这一目标?

另一件事我正在这个 groovy 脚本中编写 println 语句,但它没有记录在何处。关于调试脚本流程的任何建议我如何记录信息?

谢谢

如果它在运行时,你可以使用:

def env = System.getenv()
//Print all the environment variables.

env.each{
println it
} 
// You can also access the specific variable, say 'username', as show below 
String user= env['USERNAME']

如果它在系统 groovy 中,您可以使用:

// get current thread / Executor and current build
def thr = Thread.currentThread()
def build = thr?.executable

//Get from Env
def stashServer= build.parent.builds[0].properties.get("envVars").find {key, value -> key == 'ANY_ENVIRONMENT_PARAMETER' }

//Get from Job Params
def jobParam= "jobParamName"
def resolver = build.buildVariableResolver
def jobParamValue= resolver.resolve(jobParam)

任何 println 正在将输出发送到标准输出流,请尝试查看控制台日志。 祝你好运!