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 theBUILD_NUMBERvariable and then store this value in a mapconfigHashto retrieve it later.The string variable
BUILD_NUMBERis injected by Jenkins in the environment when a build starts and is interpolated by the pipeline Groovy script in runtime. However,1.0.BUILD_NUMBERis interpreted as if you are trying to access theBUILD_NUMBERproperty of java.math.bigDecimal class1.0and 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 classconfigHash.put('ci.jenkins.build_number', "1.0.${BUILD_NUMBER}").