0
votes

We want to define the project version for our Gradle project during the build of our project in the Jenkins pipeline, which will include a timestamp and a git-commit-id. (20180625180158-b8ad8df0dc0356a91707eaa241de7d62df6a29f2)

void defineVersion() {
sh "git rev-parse HEAD > .git/commit-id"
commitId = readFile('.git/commit-id')
timestamp =  getCurrentTimestamp()
version = timestamp+'-'+commitId
}

This function will determine the version I want to publish our artifact with. Next I use the Artifactory Gradle plugin to publish, but I can't find a way to set/override the project version. I want the jar to be published with version 20180625180158-b8ad8df0dc0356a91707eaa241de7d62df6a29f2

version = defineVersion() // how can we incorperate this version in our gradle build/publish?

gradleBuild = Artifactory.newGradleBuild()
gradleBuild.useWrapper = true
gradleBuild.deployer(
        repo: env.BRANCH_NAME == 'master' ? 'libs-releases-local' : 'libs-snapshots-local',
        server: Artifactory.server('artifactory-global'))

gradleBuild.run tasks: 'clean build artifactoryPublish'

How can we achieve this? Also I would like to pass other parameters like -x test to the run command to skip tests in this stage.

1

1 Answers

1
votes

Apparently you can add parameters throug the switches parameter: https://jenkins.io/doc/pipeline/steps/artifactory/

With this you add the necessary parameters like '-x test -Pversion=' + version

For my use case I added a version property to my build.gradle: version = "${version}" so it can be overridden with the command above.