简体   繁体   English

你如何在Jenkins构建推广步骤中推送git标签?

[英]How do you push a git tag in a Jenkins build promotion step?

I have a build promotion process modeled after this discussion (using promoted builds plugin.) In general, it works great. 我有蓝本构建推广过程中这种讨论(使用促进构建插件。)一般情况下,它的伟大工程。 However, for a few "flavors" of the promotion process (not all) I'd like to push a git tag. 然而,对于促销过程的一些“风味”(并非所有),我想推出一个git标签。 I implemented this with an "execute shell" step as one of the promotion actions. 我通过“执行shell”步骤实现了这一步骤作为促销操作之一。 This has been working well, and then today failed with the error below. 这一直运作良好,然后今天失败了,下面的错误。 I suspect I landed on a build slave where the workspace wasn't already initialized for git - and that I've been getting lucky in the past (using Cloudbees - where the build slaves are dynamically allocated.) 我怀疑我登陆了一个构建奴隶,其中工作区尚未为git初始化 - 而且我过去一直很幸运(使用Cloudbees - 动态分配构建从属)。

I've tried the "git publisher", but it seems to expect that you are in a setting where the git source plugin has already done its job. 我已经尝试了“git发布者”,但它似乎期望你处于git源插件已经完成其工作的环境中。 Has anyone been able reliably push a tag from a build promotion step ? 有没有人能够从构建促销步骤中可靠地推送标签?

+ git checkout develop
fatal: Not a git repository (or any of the parent directories): .git

This has worked so far for me: 到目前为止,这对我有用:

git tag MYTAG ${PROMOTED_GIT_COMMIT}
git push --tags

I am not sure if I simplify the issue, in my environment the promotion seems to be executed on master where the archived artifacts are. 我不确定我是否简化了问题,在我的环境中,促销似乎是在归档工件所在的master上执行的。

Disclaimer: I know nothing about Git. 免责声明:我对Git一无所知。

You should never rely on files under ${WORKSPACE} when executing promotions. 在执行促销时,您永远不应该依赖${WORKSPACE}下的文件。 At best, they may be newer than the job run promotion that you are executing, and at worst the workspace could be empty while doing a new checkout (or non-existent as in your case). 最好的情况是,它们可能比您正在执行的作业运行促销更新,并且在最坏的情况下,工作区在执行新结帐时可能是空的(或者在您的情况下不存在)。 That's why in the discussion that you linked , I am using Copy Artifacts step. 这就是为什么在您链接讨论中 ,我正在使用Copy Artifacts步骤。 Note that that step copies from archived artifacts , not from job workspace, which should always be considered temporary and transient. 请注意,该步骤从归档工件复制,而不是从作业工作区复制,应始终将其视为临时和瞬态。

If you need to rely on an SCM checkout for your promotion process, you have to either: 如果您需要依赖SCM结帐进行促销流程,则必须:

  • Perform command line checkout (it will not be tracked by Jenkins), or 执行命令行检出(Jenkins不会跟踪),或
  • Run another job with SCM checkout (all the benefits of Jenkins tracking). 使用SCM checkout运行另一项工作(Jenkins跟踪的所有好处)。

In both cases, I would assume you want to pass an SCM revision number to the promotion process (to use in command line checkout, or as parameter for calling another job). 在这两种情况下,我都假设您要将SCM修订号传递给升级过程(用于命令行检出,或作为调用另一个作业的参数)。 The "Trigger/Call builds" step has an option to pass parent SVN revision, but I don't know if it has the same option for Git. “触发/调用构建”步骤有一个选项来传递父SVN修订版,但我不知道它是否具有相同的Git选项。 In worst case, on your "build" job execution, store the Git revision to a file and archive that file with the rest of the artifacts. 在最坏的情况下,在“构建”作业执行时,将Git修订存储到文件中,并将该文件与其余工件一起存档。 In your promotion process, retrieve the saved file with "Copy Artifacts" step, and then extract the Git revision from that file. 在促销过程中,使用“复制工件”步骤检索已保存的文件,然后从该文件中提取Git修订版。 You can use EnvInject plugin to help with all that and make the extracted Git revision available as an Environment Variable for the promotion process. 您可以使用EnvInject插件来帮助完成所有这些操作,并将提取的Git修订版作为促销过程的环境变量提供。

My recommendation would be a second "Trigger/Call Builds" step in your promotion process that triggers a job dedicated to what you want, passing it a Git revision parameter. 我的建议是你的推广过程中的第二个“触发/调用构建”步骤,它触发一个专门用于你想要的工作,并传递一个Git修订版参数。

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

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