Search code examples
jenkinsjenkins-job-dsl

How to set build name in Jenkins Job DSL?


According to the documentation in https://jenkinsci.github.io/job-dsl-plugin/#method/javaposse.jobdsl.dsl.helpers.wrapper.MavenWrapperContext.buildName

Following code should update build name in Build History in Jenkins jobs:

// define the build name based on the build number and an environment variable
job('example') {
  wrappers {
    buildName('#${BUILD_NUMBER} on ${ENV,var="BRANCH"}')
  }
}

Unfortunately, it is not doing it.

Is there any way to change build name from Jenkins Job DSL script? I know I can change it from Jenkins Pipeline Script but it is not needed for me in this particular job. All I use in the job is steps.

steps {
  shell("docker cp ...")
  shell("git clone ...")
  ...
}

I would like to emphasise I am looking for a native Jenkins Job DSL solution and not a Jenkins Pipeline Script one or any other hacky way like manipulation of environment variables.


Solution

  • I have managed to solve my issue today. The script did not work because it requires build-name-setter plugin installed in Jenkins. After I have installed it works perfectly. Unfortunately, by default jobdsl processor does not inform about missing plugins. The parameter enabling that is described here https://issues.jenkins-ci.org/browse/JENKINS-37417