Jenkins - (private subnet) WebHook with Github does not trigger automatic build

时间:2015-06-15 14:28:54

标签: git github jenkins continuous-integration devops

Problem :

I am working on a CI setup to configure github - Jenkins web hook for triggering builds with code commits on github. Below are the current configuration details

  • My Jenkins is inside an AWS private subnet
  • I have plugin: "GitHub Web Hook" configured with API URL, Username and OAuth token, Test Credentials gives a success message.
  • I have "Build when a change is pushed to GitHub" selected under "Build Triggers"

Jenkins job works perfectly with the manual build. But it does not work (automatic build trigger) when a code commit is done on the github.

Need Help on:

  1. How can I debug in detail about this situation, if the "Git hub webhook" configuration test worked, can I say git hub is able to connect to my Jenkins which is in private or it does something else to test ?
  2. Please rectify / guide on the steps to get it working

2 个答案:

答案 0 :(得分:6)

经过一些忙碌的时间后,我已经达到了工作状态。以下只是我所做的总结:

  • 您可以通过两种方式完成此操作:轮询SCM或WebHooks(此处说明)
  • JenkinsURL / job / job-Name / scmPollLog是检查投票日志的地方
  • 我已将Jenkins移至公共子网(github需要与jenkins交谈)
  • 转到https://github.com/settings/tokens并创建访问令牌
  • On Jenkins>管理Jenkins>配置系统>配置GitHub Web Hook, API网址 - " https://api.github.com"用户名 - 您的github用户名, 上面创建的OAuth令牌 - 测试成功!!
  • 导航到作业配置,在Build Triggers下,选择"将更改推送到GitHub后构建"
  • 转到https://github.com/yourID/repoName/settings/hooks并添加webhook
Payload URL - http://jenkinsIP:port/github-webhook/
Content type - application/x-www-form-urlencoded
Secret - none
Which events would you like to trigger this webhook? - Just the push event
Active > Add webhook

您可以检查将更改提交到github,并且github将向您的jenkins服务器发送POST请求,这将触发构建。您可以查看最近交货部分中的日志。

enter image description here

如果可以为私人jenkins服务器执行此操作,例如使用端口转发或任何其他方式。请更新。

答案 1 :(得分:2)

鉴于此评论已闲置一段时间,我将扩展 cody.codes 评论。您可以配置一个 webhook 负载传送服务,例如 smee.io,它将拦截 GitHub 触发的 webhook。

Jenkins article 详细概述了设置说明,但简化的概述是:

  1. 发生 SCM 更改等 GitHub 事件,并触发 Webhook 触发到您配置的 Smee 频道
  2. Smee 频道(下图中的蓝色框)接收此网络钩子
  3. Jenkins 服务器订阅了您的自定义 smee 频道,发现那里有新事件,并触发您的工作。

Simplified visual overview of the communication between GitHub, Smee, and Jenkins

Jenkins 仅在此设置中建立出站连接(订阅您的 Smee 频道需要此连接),因此您的 Jenkins 服务器可以保留在您的防火墙之后。