How to set build name in Jenkins Job DSL?












1















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.










share|improve this question

























  • Possible duplicate of How to customize Jenkins build name?

    – Michael
    Nov 24 '18 at 6:29











  • The answer you have pointed to is related to Jenkins Pipeline scripts or has some hacky ways of changing the build name. I was hoping for a solution supported by Jenkins Job DSL script natively.

    – firen
    Nov 26 '18 at 22:22
















1















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.










share|improve this question

























  • Possible duplicate of How to customize Jenkins build name?

    – Michael
    Nov 24 '18 at 6:29











  • The answer you have pointed to is related to Jenkins Pipeline scripts or has some hacky ways of changing the build name. I was hoping for a solution supported by Jenkins Job DSL script natively.

    – firen
    Nov 26 '18 at 22:22














1












1








1








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.










share|improve this question
















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.







jenkins jenkins-job-dsl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 22:25







firen

















asked Nov 23 '18 at 18:15









firenfiren

5972724




5972724













  • Possible duplicate of How to customize Jenkins build name?

    – Michael
    Nov 24 '18 at 6:29











  • The answer you have pointed to is related to Jenkins Pipeline scripts or has some hacky ways of changing the build name. I was hoping for a solution supported by Jenkins Job DSL script natively.

    – firen
    Nov 26 '18 at 22:22



















  • Possible duplicate of How to customize Jenkins build name?

    – Michael
    Nov 24 '18 at 6:29











  • The answer you have pointed to is related to Jenkins Pipeline scripts or has some hacky ways of changing the build name. I was hoping for a solution supported by Jenkins Job DSL script natively.

    – firen
    Nov 26 '18 at 22:22

















Possible duplicate of How to customize Jenkins build name?

– Michael
Nov 24 '18 at 6:29





Possible duplicate of How to customize Jenkins build name?

– Michael
Nov 24 '18 at 6:29













The answer you have pointed to is related to Jenkins Pipeline scripts or has some hacky ways of changing the build name. I was hoping for a solution supported by Jenkins Job DSL script natively.

– firen
Nov 26 '18 at 22:22





The answer you have pointed to is related to Jenkins Pipeline scripts or has some hacky ways of changing the build name. I was hoping for a solution supported by Jenkins Job DSL script natively.

– firen
Nov 26 '18 at 22:22












3 Answers
3






active

oldest

votes


















2














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






share|improve this answer































    1














    Here's a minimal pipeline changing the build's display name and description. IMHO this is pretty straight forward.



    pipeline {

    agent any

    environment {
    VERSION = "1.2.3-SNAPSHOT"
    }

    stages {
    stage("set build name") {
    steps {
    script {
    currentBuild.displayName = "v${env.VERSION}"
    currentBuild.description = "#${BUILD_NUMBER} (v${env.VERSION})"
    }
    }
    }
    }
    }


    It results in the following representation in Jenkins' UI: Changed display name is shown in build history; Stage view shows the display name






    share|improve this answer
























    • jenkinsci.github.io/job-dsl-plugin/#method/… script seams to not be part of steps element

      – firen
      Dec 4 '18 at 15:34











    • @firen you linked to a job DSL documentation page. My example is in pipeline DSL and script is a valid step (see jenkins.io/doc/pipeline/steps/pipeline-model-definition/…)

      – Michael
      Dec 4 '18 at 15:38



















    0














    setBuildName("your_build_name") in a groovyPostBuild step may do the trick as well.
    Needs Groovy Postbuild Plugin.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451345%2fhow-to-set-build-name-in-jenkins-job-dsl%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      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






      share|improve this answer




























        2














        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






        share|improve this answer


























          2












          2








          2







          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






          share|improve this answer













          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







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 4 '18 at 19:36









          firenfiren

          5972724




          5972724

























              1














              Here's a minimal pipeline changing the build's display name and description. IMHO this is pretty straight forward.



              pipeline {

              agent any

              environment {
              VERSION = "1.2.3-SNAPSHOT"
              }

              stages {
              stage("set build name") {
              steps {
              script {
              currentBuild.displayName = "v${env.VERSION}"
              currentBuild.description = "#${BUILD_NUMBER} (v${env.VERSION})"
              }
              }
              }
              }
              }


              It results in the following representation in Jenkins' UI: Changed display name is shown in build history; Stage view shows the display name






              share|improve this answer
























              • jenkinsci.github.io/job-dsl-plugin/#method/… script seams to not be part of steps element

                – firen
                Dec 4 '18 at 15:34











              • @firen you linked to a job DSL documentation page. My example is in pipeline DSL and script is a valid step (see jenkins.io/doc/pipeline/steps/pipeline-model-definition/…)

                – Michael
                Dec 4 '18 at 15:38
















              1














              Here's a minimal pipeline changing the build's display name and description. IMHO this is pretty straight forward.



              pipeline {

              agent any

              environment {
              VERSION = "1.2.3-SNAPSHOT"
              }

              stages {
              stage("set build name") {
              steps {
              script {
              currentBuild.displayName = "v${env.VERSION}"
              currentBuild.description = "#${BUILD_NUMBER} (v${env.VERSION})"
              }
              }
              }
              }
              }


              It results in the following representation in Jenkins' UI: Changed display name is shown in build history; Stage view shows the display name






              share|improve this answer
























              • jenkinsci.github.io/job-dsl-plugin/#method/… script seams to not be part of steps element

                – firen
                Dec 4 '18 at 15:34











              • @firen you linked to a job DSL documentation page. My example is in pipeline DSL and script is a valid step (see jenkins.io/doc/pipeline/steps/pipeline-model-definition/…)

                – Michael
                Dec 4 '18 at 15:38














              1












              1








              1







              Here's a minimal pipeline changing the build's display name and description. IMHO this is pretty straight forward.



              pipeline {

              agent any

              environment {
              VERSION = "1.2.3-SNAPSHOT"
              }

              stages {
              stage("set build name") {
              steps {
              script {
              currentBuild.displayName = "v${env.VERSION}"
              currentBuild.description = "#${BUILD_NUMBER} (v${env.VERSION})"
              }
              }
              }
              }
              }


              It results in the following representation in Jenkins' UI: Changed display name is shown in build history; Stage view shows the display name






              share|improve this answer













              Here's a minimal pipeline changing the build's display name and description. IMHO this is pretty straight forward.



              pipeline {

              agent any

              environment {
              VERSION = "1.2.3-SNAPSHOT"
              }

              stages {
              stage("set build name") {
              steps {
              script {
              currentBuild.displayName = "v${env.VERSION}"
              currentBuild.description = "#${BUILD_NUMBER} (v${env.VERSION})"
              }
              }
              }
              }
              }


              It results in the following representation in Jenkins' UI: Changed display name is shown in build history; Stage view shows the display name







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 30 '18 at 12:54









              MichaelMichael

              1,2161912




              1,2161912













              • jenkinsci.github.io/job-dsl-plugin/#method/… script seams to not be part of steps element

                – firen
                Dec 4 '18 at 15:34











              • @firen you linked to a job DSL documentation page. My example is in pipeline DSL and script is a valid step (see jenkins.io/doc/pipeline/steps/pipeline-model-definition/…)

                – Michael
                Dec 4 '18 at 15:38



















              • jenkinsci.github.io/job-dsl-plugin/#method/… script seams to not be part of steps element

                – firen
                Dec 4 '18 at 15:34











              • @firen you linked to a job DSL documentation page. My example is in pipeline DSL and script is a valid step (see jenkins.io/doc/pipeline/steps/pipeline-model-definition/…)

                – Michael
                Dec 4 '18 at 15:38

















              jenkinsci.github.io/job-dsl-plugin/#method/… script seams to not be part of steps element

              – firen
              Dec 4 '18 at 15:34





              jenkinsci.github.io/job-dsl-plugin/#method/… script seams to not be part of steps element

              – firen
              Dec 4 '18 at 15:34













              @firen you linked to a job DSL documentation page. My example is in pipeline DSL and script is a valid step (see jenkins.io/doc/pipeline/steps/pipeline-model-definition/…)

              – Michael
              Dec 4 '18 at 15:38





              @firen you linked to a job DSL documentation page. My example is in pipeline DSL and script is a valid step (see jenkins.io/doc/pipeline/steps/pipeline-model-definition/…)

              – Michael
              Dec 4 '18 at 15:38











              0














              setBuildName("your_build_name") in a groovyPostBuild step may do the trick as well.
              Needs Groovy Postbuild Plugin.






              share|improve this answer




























                0














                setBuildName("your_build_name") in a groovyPostBuild step may do the trick as well.
                Needs Groovy Postbuild Plugin.






                share|improve this answer


























                  0












                  0








                  0







                  setBuildName("your_build_name") in a groovyPostBuild step may do the trick as well.
                  Needs Groovy Postbuild Plugin.






                  share|improve this answer













                  setBuildName("your_build_name") in a groovyPostBuild step may do the trick as well.
                  Needs Groovy Postbuild Plugin.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 29 at 14:49









                  lenkovilenkovi

                  1402310




                  1402310






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451345%2fhow-to-set-build-name-in-jenkins-job-dsl%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      404 Error Contact Form 7 ajax form submitting

                      How to know if a Active Directory user can login interactively

                      TypeError: fit_transform() missing 1 required positional argument: 'X'