简体   繁体   English

使用Artifactory Gradle插件在Jenkins Pipeline中设置项目版本

[英]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.

相关问题 Jenkins Artifactory插件不适用于最新版本的Artifactory - Jenkins Artifactory Plugin not working with recent Artifactory version Jenkins Artifactory插件(等级)未从gradle.properties中读取版本 - Jenkins Artifactory Plugin (gradle) doesn't read version from gradle.properties 使用Jenkins,Gradle Artifactory插件配置发布暂存 - Configure release staging with Jenkins, Gradle Artifactory plugin 没有使用 jenkins gradle artifactory 插件部署的工件 - No artifacts deployed with jenkins gradle artifactory plugin 较新版本的Artifactory的Jenkins Artifactory插件出现问题 - Newer version Artifactory is having problems with Jenkins Artifactory plugin Jenkins Artifactory Plugin多项目发行 - Jenkins Artifactory Plugin multi-project release 在Jenkins管道和Gradle项目中,如何使用Jenkins Nexus插件获取GAV属性以部署工件? - Jenkins pipeline and Gradle project, how can I get the GAV properties to deploy the artifact with Jenkins Nexus Plugin? Jenkins与Docker和Artifactory的管道 - Jenkins pipeline with Docker and Artifactory 如何更改Multibranch Pipeline作业中Jenkins Artifactory插件的默认超时? - How to change the default timeout for the Jenkins Artifactory plugin in a Multibranch Pipeline job? Jenkins的Artifactory插件 - 在脚本管道中的NPM安装失败 - Artifactory Plugin for Jenkins - NPM Install in scripted pipeline is failing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM