I wish to set the build name based on some condition.
Eg:
if the branch name( input parameter)= development
then build name= development
if the branch name = master then build name= master.
I can able to set the build name by using build name setter plugin but i need this based on condition.
Assuming that you use Free Style jobs, then you can use the Groovy
plugin to execute arbitrary groovy code which has access to the Java structures for the build and Jenkins.
Simply add an Execute system Groovy script
step and enter your code which determines the name, then use build.setDisplayName()
to set the name.
So similar to your example, here is a name setter which sets the name depending on the value of build parameter branch_name
:
if (build.buildVariableResolver.resolve("branch_name").equals('master')) {
build.setDisplayName("Master build #${build.getNumber()}")
} else if (build.buildVariableResolver.resolve("branch_name").equals('development')) {
build.setDisplayName("Development build #${build.getNumber()}")
} else {
build.setDisplayName("Other build #${build.getNumber()}")
}
if the branch name( input parameter) = development then build name= development
Assuming you are providing the branch name as a parameter and want to set the build name as the same using the name setter plugin, you should be able to configure it.
You can use the same parameter name as environment variable in the setter plugin as ${ENV,var="my-special-branch"}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With