How to customize Jenkins build name?

前端 未结 6 852
生来不讨喜
生来不讨喜 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: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.

提交回复
热议问题