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

groovyhudsonJenkins

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_NUMBER etc.)
  • the result of a specific build number of the current project
  • the build number of the last not successful build in the current project

At the moment I only found the following way, but it's rather limited:

def item = hudson.model.Hudson.instance.getItem("GroovyMultipleFailTest") 
def build = item.getLastBuild()
build.getNumber()

Best Answer

${manager.build.getEnvironment(manager.listener)['BUILD_NUMBER'] }
Related Topic