[英]Github + Jenkins >> How to trigger build on “Commit and Push” in code repository?
However, this is a manual trigger. 但是,这是一个手动触发器。 I mean, the build gets triggered only when a user clicks on "Build Now" in Jenkins console. 我的意思是,只有当用户点击Jenkins控制台中的“立即构建”时才会触发构建。
Actually, my requirement is to trigger a build when the changes are committed and pushed. 实际上,我的要求是在提交和推送更改时触发构建。 (that means, "Commit and Push" while checking-in changes). (这意味着,在签入更改时“提交和推送”)。
I referred to a lot of blogs and posts, and came to know about Git hooks. 我提到了很多博客和帖子,并了解了Git钩子。 I also tried creating "post-receive" hook. 我也试过创建“post-receive”钩子。 I created a hook at the location where source code is mapped (For example, "E:\\Git\\test-jenkins.git\\hooks"). 我在源代码映射的位置创建了一个钩子(例如,“E:\\ Git \\ test-jenkins.git \\ hooks”)。
#!/bin/bash
curl POST "http://localhost:8080/job/Test-Jenkins/build" --data delay=0sec
But this doesn't work. 但这不起作用。 A build is never getting triggered on "Commit and Push". “提交和推送”永远不会触发构建。 when I try copying the URL directly in the browser, it triggers a build, so I believe there is no issue with the URL. 当我尝试直接在浏览器中复制URL时,它会触发构建,所以我相信URL没有问题。 But the script itself is not getting executed. 但脚本本身并没有被执行。
Could anyone please suggest how to solve this problem? 任何人都可以建议如何解决这个问题?
Any help on this much appreciated. 任何帮助都非常感谢。
It's because Github
server will not be able to reach the Jenkins
server hosted on local, to trigger the build. 这是因为Github
服务器将无法访问本地托管的Jenkins
服务器,以触发构建。
You will either need a static IP address
or you need to map a DNS
entry to your dynamic IP. 您将需要static IP address
或者需要将DNS
条目映射到动态IP。 Also, you need to open the port 8080
for external access. 此外,您需要打开端口8080
以进行外部访问。 Only then GitHub
will be able to reach your local instance with its webhook. 只有这样, GitHub
才能通过其webhook访问您的本地实例。
Hope it helps:) 希望能帮助到你:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.