我可以让 Jenkins 从传入的参数中构建 git 标签吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7157170/
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-10 11:40:20  来源:igfitidea点击:

Can I get Jenkins to build a git tag from a passed in parameter?

gittagsjenkins

提问by dalyons

Jenkins supports parametrized builds.

Jenkins 支持参数化构建。

I have a deployment build that requires the tag to deploy to be specified via a parameter. (to deploy a particular tag to production)

我有一个部署版本,需要通过参数指定要部署的标签。(将特定标签部署到生产中)

Is there an easy way to do this with the git plugin?

有没有一种简单的方法可以使用 git 插件来做到这一点?

I tried adding a parameter TAG_NAME, and then setting branch_specifier in the git plugin section of the job to $TAG_NAME. Dosen't work. I get:

我尝试添加一个参数 TAG_NAME,然后将作业的 git 插件部分中的 branch_specifier 设置为 $TAG_NAME。行不通。我得到:

ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.

Any ideas?

有任何想法吗?

采纳答案by carlspring

Make the build parameterized and in the git URL box, put the name of the variable you've defined. For example: ${GIT_URL}. This should do it.

使构建参数化并在 git URL 框中,输入您定义的变量的名称。例如:${GIT_URL}。这应该这样做。

回答by link

Will up oooold topic, since this one is in google's top. Spent some time on this question... Short answer: Extensible choice plugin + groovy script. This allows to make dropdown menu already filled with existing tags.

将 oooold 主题,因为这是在谷歌的顶部。在这个问题上花了一些时间......简短回答:可扩展选择插件 + groovy 脚本。这允许使用现有标签填充下拉菜单。

def gettags = "git ls-remote -t [email protected]:mycompany/com.someproject.git".execute()
def tags = []
def t1 = []
gettags.text.eachLine {tags.add(it)}
for(i in tags)
    t1.add(i.split()[1].replaceAll('\^\{\}', '').replaceAll('refs/tags/', ''))
t1 = t1.unique()
return t1

Long answer here

长答案在这里

回答by Mihai Rotaru

There's Git Parameter Plugin, which allows you to do exactly that:

Git Parameter Plugin,它可以让你做到这一点:

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.

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