简体   繁体   English

发布到Jenkins中的Artifactory时,使用Git SHA提交ID作为工件版本号

[英]Using Git SHA commit ID as artifact version number when publishing to Artifactory in Jenkins

We have a Gradle project in a Git repository that Jenkins monitors for commits. 我们在Git存储库中有一个Gradle项目,Jenkins监视提交。 When a new commit comes in it kicks off the build pipeline. 当新的提交进入时,它将启动构建管道。 At the end of the pipeline it publishes the jar file to Artifactory. 在管道的末尾,它将jar文件发布到Artifactory。

I want Jenkins to use the Git SHA commit ID has the artifact version number of the published jar. 我希望Jenkins使用Git SHA提交ID具有已发布jar的工件版本号。 I see that the Jenkins Git plugin saves the commit ID in an environment variable called GIT_COMMIT. 我看到Jenkins Git插件将提交ID保存在一个名为GIT_COMMIT的环境变量中。 But how do I tell the Jenkins Artifactory plugin to use this value for the version number? 但是,如何告诉Jenkins Artifactory插件将此值用于版本号?

You don't have to abuse the file name with additional metadata, since Artifactory knows how to store the metadata for the files. 您不必滥用文件名和其他元数据,因为Artifactory知道如何存储文件的元数据。

More so, all the files built by Jenkins with Jenkins Artifactory plugin, or with Gradle with Gradle Artifactory plugin already have this information. 更重要的是,Jenkins使用Jenkins Artifactory插件或使用Gradle with Gradle Artifactory插件构建的所有文件都已拥有此信息。

Here's an example of the properties passed by Jenkins to Arifactory. 这是Jenkins传递给Arifactory的属性的示例。 As you can see, the vcs.revision includes the information you need: 如您所见, vcs.revision包含您需要的信息: 在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM