4

I want to get a value from an INI file (the version build number), and set the description of the Jenkins job based on this value. I haven't found an INI file Jenkins plugin, so I guess I would use a PowerShell or Batch script to interpret the INI file.

But what is the best way to get this value into the Jenkins pipeline job? Store it in an environment variable? Write it to a plain text file? Is there some convention for doing such things with Jenkins?

Ola Eldøy
  • 5,720
  • 7
  • 49
  • 82

1 Answers1

2

You can use the readFile Pipeline step: https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#code-readfile-code-read-file-from-workspace

This will read you the ini file into a String. When you have your ini file as String you can extract the version build number with standard groovy String parsing.

To set the build description, use this this code:

currentBuild.description = "my.build.number"
haschibaschi
  • 2,734
  • 23
  • 31
  • Perfect! And here is a link that helped me solve the groovy string parsing: http://stackoverflow.com/questions/38954913/jenkins-pipeline-extract-and-set-variables-from-properties-file-in-groovy – Ola Eldøy Apr 20 '17 at 08:32