简体   繁体   English

Github + Jenkins >>如何触发代码库中“Commit and Push”的构建?

[英]Github + Jenkins >> How to trigger build on “Commit and Push” in code repository?

  • I have setup a local instance of Jenkins on my computer, and I can access it through - " http://localhost:8080 ". 我已经在我的计算机上设置了Jenkins的本地实例,我可以通过“ http:// localhost:8080 ”访问它。
  • Created a Public Git repository, and added my ASP.NET MVC project there. 创建了一个Public Git存储库,并在那里添加了我的ASP.NET MVC项目。
  • Also configured Jenkins to build the project, and it does the job very well. 还配置了Jenkins来构建项目,它完成了很好的工作。

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:) 希望能帮助到你:)

I think that you should use "webhook & services" in your repository settings in Github. 我认为您应该在Github的存储库设置中使用“webhook&services”。 Please see the image below: 请看下面的图片: 詹金斯+ github

To implement it, you have to have a public domain for your Jenkins 要实现它,您必须拥有Jenkins的公共域

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在对私有github存储库进行推送时触发Jenkins构建 - How to trigger a Jenkins build when a push is made to a private github repository 如何让Jenkins推送到GitHub,但不会触发推送 - How to get Jenkins to push to GitHub but not trigger a build off that push 通过推送到Bitbucket存储库触发本地Jenkins构建 - Trigger local Jenkins build with a push to a Bitbucket repository 如何使用github存储库在jenkins中触发单个作业 - How to trigger a individual job in jenkins with github repository 基于新的 GitHub 版本触发 Jenkins 构建或提交到 master 分支 - Trigger Jenkins build based on a new GitHub release or commit to the master branch 为分支和提交触发 Jenkins 构建 - Trigger a Jenkins build for a branch and a commit 如何在GitHub上提交并推送到其他人的存储库? - How can I commit and push to someone else's repository on GitHub? 如何在 github 中将文件从不同目录提交并推送到同一存储库 - How to commit and push file from different directory to the same repository in github 如何将代码推送到git仓库的根目录(GitHub) - How to push code to root of git repository (GitHub) 如何将现有的源代码推送到github中的存储库? - How to push existing source code to a repository in github?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM