【问题标题】:Set project version in Jenkins Pipeline with the Artifactory Gradle plugin使用 Artifactory Gradle 插件在 Jenkins Pipeline 中设置项目版本
【发布时间】:2018-12-04 06:45:38
【问题描述】:

我们想在 Jenkins 管道中构建项目期间为 Gradle 项目定义项目版本,其中将包括时间戳和 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
}

此函数将确定我想要发布我们的工件的版本。 接下来我使用 Artifactory Gradle 插件发布,但我找不到设置/覆盖项目版本的方法。我希望 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'

我们怎样才能做到这一点?另外我想将 -x test 等其他参数传递给运行命令以跳过此阶段的测试。

【问题讨论】:

    标签: jenkins gradle jenkins-pipeline artifactory


    【解决方案1】:

    显然你可以通过switches参数添加参数:https://jenkins.io/doc/pipeline/steps/artifactory/

    您可以添加必要的参数,例如'-x test -Pversion=' + version

    对于我的用例,我在 build.gradle 中添加了一个版本属性:version = "${version}",因此可以使用上面的命令覆盖它。

    【讨论】:

    • 需要做类似的事情。因此,在 build.gradle 中添加 version = "${version}" 之后,该行是如何在 jenkinsfile 中结束的?我试过了,但它不起作用(例如版本 5): buildInfo = rtGradle.run rootDir: "/path/test", buildFile: 'build.gradle', tasks: 'clean build -Pversion = + 5'
    猜你喜欢
    • 2016-12-26
    • 2016-09-07
    • 1970-01-01
    • 2014-03-04
    • 1970-01-01
    • 1970-01-01
    • 2021-02-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多