【问题标题】:Access BUILD_NUMBER in Jenkins Promoted build plugin scripts在 Jenkins 中访问 BUILD_NUMBER 升级的构建插件脚本
【发布时间】:2016-11-14 18:39:45
【问题描述】:

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

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

谢谢

【问题讨论】:

    标签: jenkins groovy jenkins-plugins promoted-builds


    【解决方案1】:

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

    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 正在将输出发送到标准输出流,请尝试查看控制台日志。 祝你好运!

    【讨论】:

    • 在控制台日志中,println 语句未打印!
    • @Dvir669 你真的可以访问ANY_ENVIRONMENT_PARAMETER吗?我认为并非所有内容都可用于升级版本。
    猜你喜欢
    • 2017-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-08
    • 1970-01-01
    • 2022-12-05
    • 2018-10-10
    • 1970-01-01
    相关资源
    最近更新 更多