0

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.

wawawa
  • 2,835
  • 6
  • 44
  • 105
  • Welcome to SO, Cecilia! Your question in the current form does not provide enough details. You might want to refer https://stackoverflow.com/help/how-to-ask and update your question with more details and code samples specific to the problem that you are facing. – Dibakar Aditya Nov 15 '19 at 12:39
  • @DibakarAditya Hi I've already updated some details. – wawawa Nov 15 '19 at 13:29

1 Answers1

2

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}").

Dibakar Aditya
  • 3,893
  • 1
  • 14
  • 25
  • Hi thanks, I wonder is you can send me a relevant tutorial about how to set up jenkinfiles, I spent a whole weekend to learn a jenkin tutorial but it has zero content about this config file, also I'm not what to do next after this, and how can I test if I can get the version automatically. Many thanks. – wawawa Nov 17 '19 at 17:09
  • @Cecilia, you can start by reading the official documentation on getting started and writing a small very basic pipeline to understand the syntax and structure quickly without being overwhelmed. Once you get a hang of it, you can write more complex pipelines and refer forums such as this for your specific requirements. See https://jenkins.io/doc/book/pipeline/jenkinsfile/ and https://jenkins.io/doc/book/pipeline/syntax/ to begin with. – Dibakar Aditya Nov 17 '19 at 17:41