I have an xml file in my project repo which after checkout, I will like to auto increment the last value of the version number for every build. I am already accessing the version number using xmlslurper and storing this in a variable. I have something like this in my pipeline script and my xml file is just a single line script with 1.0.0.0 and I will like auto increment the last digit for every build. NB: I do not want to use jenkins's build number. That would have been easy by just changing the last digit to $BUILD_NUMBER in my project repo.
@NonCPS
String getVersion(String path)
{
def version = new xmlSlurper().parse(new File(path))
return version.toString()
}
node
{
stage ('checkout') {
.........
}
stage ('build) {
def pwd2=pwd()
def v=getVersion("${pwd2}/VersionNumber.xml")
sh ' dotnet publish path/to/project -p:Fileversion=$v '
}
}
There's no plugin for this, so I guess you can just go with groovy. If you don't like the build number, try this
For the build number approach I would suggest to keep the whole version in jenkinsfile, should be as simple as: