git 将更改推送到 GitHub 选项时的 Jenkins-Build 选项不起作用

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

Jenkins-Build when a change is pushed to GitHub option is not working

gitgithubjenkinsjenkins-pluginsjenkins-cli

提问by Anuj Balan

Jenkins is running on localhost. I have my repository in GitHub. I have the option to 'Build when a change is pushed to GitHub' checked.

Jenkins 在本地主机上运行。我在 GitHub 中有我的存储库。我可以选择“在将更改推送到 GitHub 时构建”选项。

When I click 'Build Now', build is done successfully, no issues there. But when am committing code to my repository, auto build is not happening. I can access GitHub from my system as the repository is public and I believe even Jenkins should be able to detect it. I know there is a polling option but I want Jenkins to build when change is detected in repository(as this is what we have been trying to achieve).

当我单击“立即构建”时,构建成功完成,没有问题。但是当我将代码提交到我的存储库时,不会发生自动构建。我可以从我的系统访问 GitHub,因为存储库是公开的,我相信即使 Jenkins 也应该能够检测到它。我知道有一个轮询选项,但我希望 Jenkins 在存储库中检测到更改时构建(因为这是我们一直在努力实现的目标)。

Configuration:

配置:

Jenkins 1.615

詹金斯 1.615

Git Plugin 2.3.5

Git 插件 2.3.5

Git Client Plugin 1.17.1

Git 客户端插件 1.17.1

————————————————————————————————————————————

———————————————————————————————————————————————

EDIT: "Build when a change is pushed to GitHub" option has been renamed to "GitHub hook trigger for GITScm polling" in most recent version of GitHub plugin. (thanks to @smrubin's feedback.)

编辑:在最新版本的 GitHub 插件中,“将更改推送到 GitHub 时构建”选项已重命名为“用于 GITScm 轮询的 GitHub 挂钩触发器”。(感谢@smrubin 的反馈。)

回答by mainframer

I suspect you missed the webhook url.

我怀疑你错过了webhook url.

Besides checking the Build when a change is pushed to GitHuboption, you should also add the webhook url into your Github repository to get the Auto triggermechanism to work and here is how:

除了检查该Build when a change is pushed to GitHub选项外,您还应该将 webhook url 添加到您的 Github 存储库中以使自动触发机制起作用,方法如下:

Go to your Github repository:

转到您的 Github 存储库:

Settings--> Webhooks&Services-->Service--> Add Services--> Choose "Jenkins (GitHub plugin)"

设置--> Webhooks&Services-->Service-->添加服务-->选择“Jenkins(GitHub插件)”

Then fill in the Jenkins hook urlwith your jenkins url like this: http://your_jenkins_url/github-webhook/enter image description here

然后Jenkins hook url像这样填写你的 jenkins url: http://your_jenkins_url/github-webhook/在此处输入图片说明



And, VERY IMPORTANT, since you are installing your jenkins server in your localhost, please be aware that you shouldn'tfill in above Jenkins hook url like http://localhost:8080/github-webhook/because Github is not able to recognize localhostor 127.0.0.1or 192.168.*.*.

而且,非常重要,因为要安装在本地主机的詹金斯服务器,请注意,你不应该上述詹金斯钩网址填写喜欢http://localhost:8080/github-webhook/,因为Github上是无法识别localhost127.0.0.1192.168.*.*

Either you should use an externally accessible DNS name or an IP address, which can be recognized by Github.

您应该使用可被 Github 识别的外部可访问的 DNS 名称或 IP 地址。

回答by AskYous

I had the same problem and solved it. The problem was that the URL had to end with a /. Meaning:

我遇到了同样的问题并解决了它。问题是 URL 必须以/. 意义:

http://<jenkinsurl>:8080/github-webhook/?

http://<jenkinsurl>:8080/github-webhook/?

http://<jenkinsurl>:8080/github-webhook?

http://<jenkinsurl>:8080/github-webhook?

(Notice the missing /at the end.)

(注意最后的缺失/。)

回答by suprakash

Actually if you do the webhook settings from Jenkins -> Github plugin configuration(mentioned above), you will still see webhooks get created in github. So, above two approaches basically doing the same thing.

实际上,如果您从Jenkins -> Github plugin configuration(上面提到的)中进行 webhook 设置,您仍然会看到在 github 中创建了 webhooks。所以,上述两种方法基本上做同样的事情。

I personally like it to create webhook from Github, because in this way you don't have to share or store github user info in jenkins.

我个人喜欢从 Github 创建 webhook,因为这样你就不必在 jenkins 中共享或存储 github 用户信息。

Steps :

脚步 :

  1. Login into Github (with Admin)

  2. Go to the repository you want to hook with jenkins

  3. Click on settings tab -> webhooks & services
  4. Click on Add Webhook.
  5. Enter payload url : like : http://:8080/github-webhook/
  6. Select content type as json.
  7. you are done.
  1. 登录 Github(使用管理员)

  2. 转到要与 jenkins 挂钩的存储库

  3. 单击设置选项卡 -> 网络钩子和服务
  4. 单击添加 Webhook。
  5. 输入有效载荷 url :如:http://:8080/github-webhook/
  6. 选择内容类型为 json。
  7. 你完成了。

Now you do the changes and commit , you will see jenkins build get trigger automatically. Don't forget to do the settings in jenkins jobs to start the build when push code in github.

现在您进行更改并提交,您将看到 jenkins build 自动触发。在 github 中推送代码时,不要忘记在 jenkins 作业中进行设置以启动构建。

回答by Jirong Hu

The GitHub plugin (https://wiki.jenkins-ci.org/display/JENKINS/GitHub+Plugin) mentioned two ways: manual mode and automatic mode. mainframer gives the answer to the manual mode. Today I found something new. mainframer's add to the service doesn't allow me to add multiple Jenkins's instance, so I add the others add the Webhook as shown below. It also works fine.

GitHub 插件(https://wiki.jenkins-ci.org/display/JENKINS/GitHub+Plugin)提到了两种方式:手动模式和自动模式。mainframer 给出了手动模式的答案。今天我发现了一些新东西。mainframer 对服务的添加不允许我添加多个 Jenkins 的实例,所以我添加了其他人添加了 Webhook,如下所示。它也工作正常。

I wanted to include a picture here but my id doesn't have the right to do so.

我想在此处添加图片,但我的 ID 无权这样做。