I have a Jekinsfile configuration for my project, I want to make some changes to the file in order to get automatic build number.
I added 1.0.BUILD_NUMBER by myself, I'm new to this jenkins pipeline, feeling very confused can anyone help me? Been struggling for the whole morning. Found lots of tutorials and articles online but none of them seem relevant because my jenkins file has been set up and can commit to gitlab repo master and can trigger the jenkins run now, not sure what to do next to get automate versioning updates.
From the question, I understand that you are trying to append 1.0.
before the BUILD_NUMBER
variable and then store this value in a map configHash
to retrieve it later.
The string variable BUILD_NUMBER
is injected by Jenkins in the environment when a build starts and is interpolated by the pipeline Groovy script in runtime. However, 1.0.BUILD_NUMBER
is interpreted as if you are trying to access the BUILD_NUMBER
property of java.math.bigDecimal class 1.0
and returns an error.
What you need to use here is Groovy string concatenation either as java.lang.String class configHash.put('ci.jenkins.build_number', '1.0.' + BUILD_NUMBER)
or groovy.lang.GString class configHash.put('ci.jenkins.build_number', "1.0.${BUILD_NUMBER}")
.