[英]Jenkins multibranch pipeline: how to get most recent git tag?
My project build relies on git tags to determine the version to use for an artifact.我的项目构建依赖于 git 标签来确定用于工件的版本。 I'm trying to create a Jenkins multibranch pipeline.我正在尝试创建一个 Jenkins 多分支管道。 That means, I need somehow to get an equivalent of the output of这意味着,我需要以某种方式获得相当于 output 的
git describe --tags
into my Jenkins pipeline.进入我的 Jenkins 管道。 No matter what I do with all kind of "Advanced behaviors", I get a detached HEAD and git saying it has nothing to describe.无论我对各种“高级行为”做什么,我都会得到一个分离的 HEAD 和 git 说它没有什么可描述的。
This document https://jenkins.io/doc/pipeline/steps/workflow-scm-step/ mentions $class: GitTagMessageExtension
with an optional boolean parameter useMostRecentTag
, which, by description should provide exactly what I need, but I cannot find the equivalent for it in pipeline snippet generator, and when, in Jenkisfile, I include本文档https://jenkins.io/doc/pipeline/steps/workflow-scm-step/提到$class: GitTagMessageExtension
带有可选的 boolean 参数useMostRecentTag
,根据描述应该提供我需要的确切信息,但我找不到在管道片段生成器中等效于它,并且在 Jenkisfile 中,我包括
checkout(
[$class: 'GitSCM',
branches: [[name: '**']],
doGenerateSubmoduleConfigurations: false,
extensions: [
[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
[$class: 'GitTagMessageExtension', useMostRecentTag:true]
],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'xxx', url: 'xxx']]
]
)
I'm getting an error我收到一个错误
java.lang.UnsupportedOperationException: no known implementation of class hudson.plugins.git.extensions.GitSCMExtension is named GitTagMessageExtension
EDIT:编辑:
As pointed by @ioannis-barakos, the GitTagMessageExtension plugin was missing.正如@ioannis-barakos 所指出的,缺少 GitTagMessageExtension 插件。 However, after installing it, the promise of但是,安装后,promise 的
If you ticked the Use most recent tag option, and the revision checked out has no git tag associated with it, the parent commits will be searched for a git tag, and the rules stated above will apply to the first parent commit with a git tag.如果您勾选了使用最近的标签选项,并且检出的修订版没有与之关联的 git 标记,则将在父提交中搜索 git 标记,并且上述规则将适用于第一个带有 ZBA9F11ECC33497D9EFDC2B 标记的父提交.
doesn't hold.不成立。 It just runs git describe --tags <commit-hash>
against detached head and exports exactly nothing.它只是针对分离的头运行git describe --tags <commit-hash>
并且什么都不导出。
So, does anyone know how to handle it?那么,有人知道如何处理吗? What am I missing?我错过了什么?
It was all false alarm: I just forgot to git push --tags
这都是虚惊一场:我只是忘了git push --tags
There is one counter-intuitive catch, though: ticking "Discover Tags" is not enough, one has to also choose "Advanced clone behaviors" and tick "Fetch tags"但是,有一个违反直觉的问题:勾选“发现标签”是不够的,还必须选择“高级克隆行为”并勾选“获取标签”
You probably do not have the Git Tag Message Plugin
installed in your Jenkins.您可能没有在 Jenkins 中安装Git Tag Message Plugin
。
The GitTagMessageExtension
is provided by that plugin (as in here ) GitTagMessageExtension
由该插件提供(如此处)
Make sure that you have the following plugin installed in your Jenkins plugins.确保在 Jenkins 插件中安装了以下插件。
Below is a working example that searches for tags in all branches (origin/**).下面是一个在所有分支 (origin/**) 中搜索标签的工作示例。 Have in mind that a credentialsId should have been configured in jenkins holding the username/password of the jenkins account and a RelativeTargetDirectory
class should be set for the download/clone location.请记住,应该已经在 jenkins 中配置了凭据 ID,其中包含 jenkins 帐户的用户名/密码,并且应该为下载/克隆位置设置RelativeTargetDirectory
class。
script {
checkout([
$class: 'GitSCM',
branches: [[name: "origin/**"]],
doGenerateSubmoduleConfigurations: false,
extensions: [[
$class: 'RelativeTargetDirectory',
relativeTargetDir: "/tmp/jenkins/git"],
[$class: 'CloneOption', depth: 0, noTags: false, reference: '', shallow: false],
[$class: 'GitTagMessageExtension', useMostRecentTag:true]
],
submoduleCfg: [],
userRemoteConfigs: [[
credentialsId: 'ioannis.barakos',
url: 'https://git.example.com/git/example'
]]
])
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.