git 如何在Node配置中获取Jenkins中的git标签名称

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32390788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:21:05  来源:igfitidea点击:

How to get the git tag name in Jenkins in Node configuration

gitjenkinsnunit

提问by JaiK

We re using node configuration in Jenkins.In the Post-build Actions we have Git Publisher which has tags to Push e.g 5.1.0.$BUILD_NUMBER.This now becomes the new build number and is used as the release number for testing

我们在 Jenkins 中使用节点配置。在构建后操作中,我们有 Git Publisher,它具有要推送的标签,例如 5.1.0.$BUILD_NUMBER。这现在成为新的构建号并用作测试的发布号

I wanted to access this tag for all the remaining jobs so that I can create the Test report XMLs something with 5.1.0.$BUILD_NUMBER+myjob.xml so that its related to that unique build number.

我想访问所有剩余作业的此标记,以便我可以使用 5.1.0.$BUILD_NUMBER+myjob.xml 创建测试报告 XML,以便它与该唯一版本号相关。

However I am not sure how can I retrieve the Git tags in all the individual jobs.I am not too sure that I want to use Global variable string property since its a node configuration where on one node/box there a different build and on other there is a different one.The Global property could overwrite the build versions on each other ?

但是我不确定如何在所有单个作业中检索 Git 标签。我不太确定我想使用全局变量字符串属性,因为它是一个节点配置,在一个节点/框上有不同的构建,而在其他有一个不同的。全局属性可以覆盖彼此的构建版本吗?

回答by Thomasleveil

If you want to pick a tag when running a new job, you can use the Git Parameter Plugin. With this plugin you have new options when you add parameters to your job.

如果要在运行新作业时选择标签,可以使用Git 参数插件。使用此插件,当您向作业添加参数时,您有新的选择。

This plugin allows you to assign git tag or revision number as parameter in Parametrized builds. There is no need to set up anything special, this plugin will read your default configuration from Git Plugin.

It firstly fetching (by git fetch) current repository, and listing all the tags/sha1's to choose from.

You can select the following sorting options for tags/revision/branches/branches_or_tags

  • none
  • descending
  • ascending
  • ascending smart
  • descending smart

For the smart variants the compare treats a sequence of digits as a single character. Contributed by Graeme Hill.

这个插件允许你在参数化构建中分配 git 标签或修订号作为参数。不需要设置任何特殊的东西,这个插件会从 Git Plugin 读取你的默认配置。

它首先获取(通过 git fetch)当前存储库,并列出所有可供选择的标签/sha1。

您可以为 tags/revision/branches/branches_or_tags 选择以下排序选项

  • 没有任何
  • 下降
  • 上升
  • 上升聪明
  • 下降智能

对于智能变体,比较将数字序列视为单个字符。由格雷姆希尔贡献。



There is also the Git Tag Message Pluginwhich, for any build, will discover if any tag is matching the current commit used for the build. If a tag is found, it's name will be set in the GIT_TAG_NAMEenvironment variable.

还有Git 标签消息插件,对于任何构建,它都会发现是否有任何标签与用于构建的当前提交匹配。如果找到一个标签,它的名称将在GIT_TAG_NAME环境变量中设置。

Exports the name and message for a git tag as environment variables during a build.

If the revision checked out during a build has a git tag associated with it, its name will be exported during the build as the GIT_TAG_NAME environment variable. If a message was specified when creating the tag (e.g. via git tag -m "..."), then that message will also be exported during the build, as the GIT_TAG_MESSAGE > environment variable.

If the revision has more than one tag associated with it, only the most recent tag will be taken into account. However, if your refspec includes "refs/tags" — i.> e. builds are only triggered when certain tag names or patterns are matched — then the exact tag name that triggered the build will be used, even if it's not the most recent tag for this commit.

在构建期间将 git 标记的名称和消息导出为环境变量。

如果在构建期间检出的修订有一个与之关联的 git 标签,则其名称将在构建期间作为 GIT_TAG_NAME 环境变量导出。如果在创建标签时指定了一条消息(例如通过 git tag -m "..."),那么该消息也将在构建期间作为 GIT_TAG_MESSAGE > 环境变量导出。

如果修订有多个与其相关联的标签,则只会考虑最近的标签。但是,如果您的 refspec 包含“refs/tags”——i.> e. 只有在匹配某些标签名称或模式时才会触发构建——然后将使用触发构建的确切标签名称,即使它不是此提交的最新标签。