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
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"
It is also possible to set build name "manually", using Jenkins Groovy plugin. Just follow these steps:
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.
[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"}
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}"
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
To modify the default display Name use currentBuild.displayName = "#${BUILD_NUMBER}, branch ${BRANCH}"