git 当推送到私有 github 存储库时如何触发 Jenkins 构建

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

How to trigger a Jenkins build when a push is made to a private github repository

gitpluginsgithubbuild-processjenkins

提问by Kim Stacks

My Jenkins Continuous Integration Server is on running on a Ubuntu host, configured as follows:

我的 Jenkins 持续集成服务器在 Ubuntu 主机上运行,​​配置如下:

  • Jenkins v 1.463
  • github-api 1.23
  • Jenkins GIT plugin 1.1.18
  • GitHub plugin 1.2
  • 詹金斯 v 1.463
  • github API 1.23
  • 詹金斯 GIT 插件 1.1.18
  • GitHub 插件 1.2

Polling SCM works.This is important to say because I want you to know my other jenkins related configuration is working well except this post build trigger nonsense.

轮询 SCM 有效。这很重要,因为我想让你知道我的其他 jenkins 相关配置运行良好,除了这个 post build trigger 废话。

I want to configure Jenkins so that when changes are pushed to a development branch in a private github repositorythis will then trigger a build that incorporates the most recent changes.

我想配置 Jenkins,以便在将更改推送到私有 github 存储库中的开发分支时,这将触发包含最新更改的构建。

The repo is under my personal github account as owner. Let's call this owner

该 repo 作为所有者位于我的个人 github 帐户下。让我们打电话给这位业主

I am including another github.com account as collaborator. Let's call this collaborator

我包括另一个 github.com 帐户作为合作者。让我们称这个合作者为

The reason I am doing this is because in case I am no longer involved in the project, somebody else can carry on with the maintenance.

我这样做的原因是,如果我不再参与该项目,其他人可以继续进行维护。

The SSH keys for the jenkins user in ubuntu are stored under collaborator

ubuntu 中 jenkins 用户的 SSH 密钥存储在collaborator 下

I have consulted the following links:

我查阅了以下链接:

http://nepalonrails.tumblr.com/post/14217655627/set-up-jenkins-ci-on-ubuntu-for-painless-rails3-app-ci

http://nepalonrails.tumblr.com/post/14217655627/set-up-jenkins-ci-on-ubuntu-for-painless-rails3-app-ci

https://issues.jenkins-ci.org/browse/JENKINS-10391

https://issues.jenkins-ci.org/browse/JENKINS-10391

https://wiki.jenkins-ci.org/display/JENKINS/Github+Plugin

https://wiki.jenkins-ci.org/display/JENKINS/Github+Plugin

http://kohsuke.org/2011/12/01/polling-must-die-triggering-jenkins-builds-from-a-git-hook/

http://kohsuke.org/2011/12/01/polling-must-die-triggering-jenkins-builds-from-a-git-hook/

https://wiki.jenkins-ci.org/display/JENKINS/Logging

https://wiki.jenkins-ci.org/display/JENKINS/Logging

http://blog.cloudbees.com/2012/01/better-integration-between-jenkins-and.html

http://blog.cloudbees.com/2012/01/better-integration-between-jenkins-and.html

None of it is not working. Some look a bit dated or even contradictory.

没有一个不起作用。有些看起来有点过时甚至矛盾。

I have added github.com to knownhosts for jenkins ubuntu user. I have added the github webhook.

我已经为 jenkins ubuntu 用户添加了 github.com 到 knownhosts。我已经添加了 github webhook。

I have tried manual and auto github webhook setup in jenkins.

我在 jenkins 中尝试过手动和自动 github webhook 设置。

Nothing works.

没有任何作用。

I need a step by step guide on how to achieve this without polling github.

我需要一个关于如何在不轮询 github 的情况下实现这一目标的分步指南。

回答by acoulton

I had a similar problem, and after looking at the main Jenkins System LogI saw the following:

我遇到了类似的问题,在查看了主要的 Jenkins系统日志后,我看到了以下内容:

Feb 15, 2013 8:35:44 PM hudson.security.csrf.CrumbFilter doFilter
WARNING: No valid crumb was included in request for /github-webhook/.  Returning 403.

The solution is to switch off the CSRF protection - Manage Jenkins > Configure System > Prevent Cross Site Request Forgery exploits. The checkbox is just at the bottom of the first configuration section. After that it all seemed to work happily.

解决方案是关闭 CSRF 保护 - 管理 Jenkins > 配置系统 > 防止跨站点请求伪造漏洞。该复选框位于第一个配置部分的底部。在那之后,一切似乎都很愉快。

回答by recampbell

Create a logger with trace level logging for the com.cloudbees.jenkinscategory under your /logurl (Manage Jenkins-> System logs).

com.cloudbees.jenkins您的/logurl下的类别创建一个具有跟踪级别日志记录的记录器(管理 Jenkins-> 系统日志)。

Verify that there is a Webhook URLentry under the Service Hookssection of your repository administration screen.

验证存储库管理屏幕的Service Hooks部分下是否有Webhook URL条目。

Click test hookand you should see some log activity under your newly created logger.

单击测试挂钩,您应该会在新创建的记录器下看到一些日志活动。

Finally, check the GitHub Pollinglog action on the build which you have configured to be triggered by GitHub pushes.

最后,检查您已配置为由 GitHub 推送触发的构建的GitHub 轮询日志操作。

A common mistake is testing commit hooks like this without having a change present.

一个常见的错误是在没有更改的情况下测试这样的提交钩子

The hook is only used to prompt a poll and won't perform a build unless changes are detected.

该钩子仅用于提示轮询,除非检测到更改,否则不会执行构建。