How to customize Jenkins build name?

前端 未结 6 845
生来不讨喜
生来不讨喜 2021-02-05 01:13

When I run a job in Jenkins, each build is given a name that shows in the UI in Build History that\'s basically the current date and time.

I\'d like to be able to put in

相关标签:
6条回答
  • 2021-02-05 01:51

    Caveat: this only works in *nix environments. For individual shell steps you can execute <command> instead as:

    /usr/bin/env JOB_NAME="Old JOB_NAME: ${JOB_NAME}" <command>
    

    Assuming your project is called "myproject", <command> would see the JOB_NAME environment variable as "Old JOB_NAME: myproject"

    0 讨论(0)
  • 2021-02-05 01:54

    It is also possible to set build name "manually", using Jenkins Groovy plugin. Just follow these steps:

    1. Generate a new build name. If you are going to perform it in the separate job step, you may need to save it to properties file, for example with name "newVersion" and perform an "Inject environment variables" step with Jenkins EnvInject plugin.
    2. Next step - run a System Groovy script:

      def build = Thread.currentThread().executable
      assert build
      def newBuildName = build.getEnvironment().get('newVersion')
      try {
          if (newBuildName) build.displayName = newBuildName
          println "Build display name is set to ${newBuildName}"
      } catch (MissingPropertyException e) {}
      

    As you can see, we are using a build.displayName variable here. Its value is a visible build name in Jenkins.

    0 讨论(0)
  • 2021-02-05 01:55

    [replying to Patrice M.'s comment above, just I don't have enough reputation to comment]:

    The Build Name Setter plugin can express a variety of variables, including environment variables, when used in conjunction with the Token Macro plugin. Furthermore, build parameters are also available as environment variables; so, for example, if your build has a parameter "MYPARAM", then you can simply use it (assuming you have installed the Token Macro plugin) in the build name like this:

    Built with parameter MYPARAM: ${ENV, var="MYPARAM"}
    
    0 讨论(0)
  • 2021-02-05 01:57

    Sounds like the Build Name Setter plugin.

    But if you're using Pipeline, you can do something like this:

    currentBuild.description = "#${BUILD_NUMBER}, branch ${BRANCH}"
    
    0 讨论(0)
  • 2021-02-05 01:58

    This plugin "Build name setter plugin" may help you. As a source for build name you can use a text file on a disk or an environment variable also you can combine the plugin with such plugin as EnvInject

    0 讨论(0)
  • 2021-02-05 01:59

    To modify the default display Name use currentBuild.displayName = "#${BUILD_NUMBER}, branch ${BRANCH}"

    0 讨论(0)
提交回复
热议问题