git 使用 Jenkins(GitHub 插件)接收提交 ID

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

Receiving the commit id with Jenkins (GitHub plugin)

gitgithubjenkins

提问by renanreismartins

When we push some changes to github we can use Github services to trigger a build. Does the service provide the commit id?

当我们向 github 推送一些更改时,我们可以使用 Github 服务来触发构建。该服务是否提供提交 ID?

Do you know how I can get that information?

你知道我怎样才能得到这些信息吗?

I need the commit it to trigger the build for that specific id. (Passing the commit id in the field "Branch Specifier (blank for 'any') ").

我需要提交它来触发该特定 ID 的构建。(在字段“分支说明符('any' 的空白)”中传递提交 ID)。

As described here git pluginbut seems I'm not receiving the commit id from git.

如此处git plugin 所述,但似乎我没有收到来自 git 的提交 ID。

I see my commit id in the post build actions, but not at the moment of the cheking out the code.

我在后期构建操作中看到了我的提交 ID,但在检查代码时没有。

Thanks in advance.

提前致谢。

回答by topher

If you're using the Git Plugin (https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin) to check out your code in Jenkins, then you should be able access the GIT_COMMIT environment variable during any build steps.

如果您使用 Git 插件 ( https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin) 在 Jenkins 中检查您的代码,那么您应该能够在任何构建期间访问 GIT_COMMIT 环境变量脚步。

There are other useful environment variables defined as well (GIT_BRANCH, GIT_PREVIOUS_COMMIT, etc.) that you may find helpful.

还定义了其他有用的环境变量(GIT_BRANCH、GIT_PREVIOUS_COMMIT 等),您可能会发现它们很有帮助。

回答by Christopher Orr

The GitHub webhooks UI doesn't provide the possibility to pass in parameters to the /git/notifyCommitURL, such as the commit SHA1.

GitHub webhooks UI 不提供将参数传递到/git/notifyCommitURL的可能性,例如提交 SHA1。

There is however the GitHub service "Jenkins (GitHub plugin)" which passes a JSON payload to Jenkins for each commit, containing a bunch of information, including the commit SHA1.

然而,GitHub 服务“Jenkins(GitHub 插件)”为每次提交将 JSON 有效负载传递给 Jenkins,其中包含一堆信息,包括提交 SHA1。

If you enable, under Build Triggers, the "Build when a change is pushed to GitHub" option, you may get the behaviour you're looking for.

如果您在构建触发器下启用“将更改推送到 GitHub 时构建”选项,您可能会得到您正在寻找的行为。