0

I have an issue with my pipeline. I have an XML file in my project repo and I will like to read this file and change values after my checkout stage.

verNum.xml

<Version>1.0.0 </Version>

and my jenkinsfile

node {
    stage ('checkout') {
    .......
    }
    stage ('readfile') {
        readFile("verNum.xml")
    }
}

I would increment the last digit of the version number with my build number. say something like this 1.0.${BUILD_NUMBER}.

Your help is highly welcomed.

Talha Junaid
  • 2,351
  • 20
  • 29
Leroi
  • 349
  • 4
  • 21
  • You should be able to modify [this groovy example](https://stackoverflow.com/questions/2245641/load-modify-and-write-an-xml-document-in-groovy) to use readfile and writefile – Rich Duncan Jan 14 '19 at 21:26
  • what are you using for building? mvn? gradle? anything else? Normally this is part of the packaging process where you actually give the version number as parameter. – hakamairi Jan 15 '19 at 08:20
  • @hakamairi I am using dotnet. I know this can be done using the -p flag to increment version number in project files.However, i want to use a different approach to that by first reading this xml file where the version number is stated, and replace this version number with the version number in my .csproj file – Leroi Jan 16 '19 at 06:53
  • Hmm.. may I suggest you to reconsider -p flag ;) – hakamairi Jan 16 '19 at 06:58

1 Answers1

-1

You can use linux cmd: sed to replace text.

sh '''
   sed -r -i 's/(<Version>1.0.)[0-9]*(.*)/\\1'$BUILD_NUMBER'\\2/' verNum.xml
'''
yong
  • 13,357
  • 1
  • 16
  • 27