[英]Set project version in Jenkins Pipeline with the Artifactory Gradle plugin
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. 我们希望在Jenkins管道中的项目构建期间为Gradle项目定义项目版本,其中将包括时间戳和git-commit-id。 ( 20180625180158-b8ad8df0dc0356a91707eaa241de7d62df6a29f2 )
( 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.
接下来,我使用Artifactory Gradle插件进行发布,但是找不到设置/覆盖项目版本的方法。 I want the jar to be published with version 20180625180158-b8ad8df0dc0356a91707eaa241de7d62df6a29f2
我希望该jar版本发布为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.
另外,我想在此阶段将其他参数(如-x test)传递给run命令以跳过测试。
Apparently you can add parameters throug the switches
parameter: https://jenkins.io/doc/pipeline/steps/artifactory/ 显然,你可以添加参数通过量的
switches
参数: https://jenkins.io/doc/pipeline/steps/artifactory/
With this you add the necessary parameters like '-x test -Pversion=' + version
这样,您就可以添加必要的参数,例如
'-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. 对于我的用例,我在build.gradle中添加了一个version属性:
version = "${version}"
因此可以用上面的命令覆盖它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.