从 Jenkins 管道脚本中创建 git 标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42550991/
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
Create git tag from within Jenkins pipeline script
提问by octavian
Within my Jenkins pipeline script, I would like to do something like this:
在我的 Jenkins 管道脚本中,我想做这样的事情:
sh("git tag ${BUILD_NUMBER}")
However, this wouldn't work if git isn't found on the shell.
但是,如果在 shell 上找不到 git,这将不起作用。
Is there any Jenkins plugin that can do this from a Jenkins pipeline script?
是否有任何 Jenkins 插件可以通过 Jenkins 管道脚本执行此操作?
回答by eyalstoler
There is no plugin support for this currently but might be in the future:
https://issues.jenkins-ci.org/browse/JENKINS-28335
目前没有对此的插件支持,但将来可能会支持:https:
//issues.jenkins-ci.org/browse/JENKINS-28335
While you go over this Jira issue take a look at Andrey Makeev's temporary solution. also documented here.
在您查看此 Jira 问题时,请查看 Andrey Makeev 的临时解决方案。也记录在这里。
回答by rbellamy
Here's how I do it, where shell
and Version
are custom functions and class, respectively, and shell
is a drop-in replacement for the sh
function:
以下是我的做法,分别是自定义函数和类,其中shell
和Version
是shell
该sh
函数的替代品:
void gitTag(Version releaseVersion) {
sshagent(['devops_deploy_DEV']) {
shell 'git tag -d $(git tag)'
shell 'git fetch --tags'
echo "New release version ${releaseVersion.normalVersion}"
shell "git tag -fa ${releaseVersion.normalVersion} -m 'Release version ${releaseVersion.normalVersion}'"
}
}
You can find the source for this here.
你可以在这里找到它的来源。
回答by Christopher
You can use the Git-Client pluginto make things like this:
sh "git tag build_${gitCommit}"
你可以使用Git-Client 插件来做这样的事情:
sh "git tag build_${gitCommit}"