How to get specific information about the current build project in Jenkins with Groovy?

后端 未结 6 1460
闹比i
闹比i 2021-02-13 10:50

In Jenkins/Hudson, with the help of a Postbuild Groovy script, I would like to get one of the following:

  • an environment variable (e.g. current JOB_NAME, BUILD_NUMB
相关标签:
6条回答
  • 2021-02-13 11:04

    The only way I got it to work for me was with build.properties.environment.BUILD_NUMBER

    0 讨论(0)
  • 2021-02-13 11:04

    Using Jenkins v2.17 this works for me:

    echo "BUILD_NUMBER=${env.BUILD_NUMBER}"

    0 讨论(0)
  • 2021-02-13 11:08

    an environment variable (e.g. current JOB_NAME, BUILD_NUMBER etc.)

    String jobName = System.getenv('JOB_NAME')
    
    0 讨论(0)
  • 2021-02-13 11:09

    Bo Persson had the best answer, but was a little short.

    To access the environment variables from the build in the Groovy Postbuild, you can grab them from the build. This sample code is useful for dumping all of the BUILD's environment variables to the console:

    manager.build.getEnvironment(manager.listener).each {
        manager.listener.logger.println(it);
    }
    
    0 讨论(0)
  • 2021-02-13 11:10

    If you're using Groovy script within "Env Inject", you can get current build and current job by:

    currentJob.getName()
    currentBuild.toString()
    
    0 讨论(0)
  • 2021-02-13 11:11
    ${manager.build.getEnvironment(manager.listener)['BUILD_NUMBER'] }
    
    0 讨论(0)
提交回复
热议问题