I currently have a Jenkins DSL script defining my release pipeline(below). I was wondering if there is a way to automatically increase the version number of the released artifact for every build, so that I can publish it to Nexus with a new unique version number, rather than having to set it manually. I have used a plugin in the past that does this automatically with regular Jenkins jobs but I can't figure out how to do so with the pipeline script.
node('master') {
//input 'Proceed?'
stage 'Checkout'
checkout scm
stage 'Build'
dir('./collector') {
sh "./gradlew clean build -Penv=${ENVIRONMENT}"
}
stage 'Flyway Migrate'
dir('./database') {
sh "./gradlew flywayMigrate -i -Penv=${ENVIRONMENT}"
}
stage 'Run cucumber Tests'
dir('./collector') {
sh "./gradlew cucumber -Penv=${ENVIRONMENT}"
}
stage 'Publish artifact to Nexus'
dir('./collector') {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'NEXUS_PASSWORD',
usernameVariable: 'NEXUS_USERNAME', passwordVariable: 'NEXUS_PASSWORD']]) {
sh ("./gradlew publish -Pnexus_username=" + env.NEXUS_USERNAME+" -Pnexus_password=" + env.NEXUS_PASSWORD+ " -Penv=${ENVIRONMENT}--stacktrace")
}
}
//stage ''
}