Jenkins对特定分支触发器的git commit也会为其他分支构建作业 [英] Jenkins git commit for specific branch triggers build jobs for other branches too

查看:192
本文介绍了Jenkins对特定分支触发器的git commit也会为其他分支构建作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个内部企业Github存储库,并且我有多个功能分支. 我在触发特定分支上的构建时遇到问题. 我已经为每个功能分支配置了作业.一个功能分支只有一项詹金斯工作. 我第一次提交代码时,也会触发其他分支的作业构建.

We have a internal enterprise Github repo, and i have multiple feature branches. I am facing a issue with triggering a build on a specific branch. I have configured jobs for each of the feature branches. There is one jenkins job for one feature branch. The first time i commit a code, it also triggers builds for jobs with other branches.

重现该问题的步骤:

1.我们有一个内部的企业版Github.对于我的仓库,我已经为github设置了webhook,如下所示

1.We have a internal Github for enterprise. For my repo, i have setup webhook for github as below

 Settings -> Webhooks & Services -> Services
 Select Jenkins (GitHub plugin) 
 Jenkins Hook Url: http://************/jenkins/github-webhook/

2.对于我在github repo中的3个分支:branch1,branch2,branch3,我在jenkins中创建了三个作业:Job1,Job2,Job3,其SCM如下配置

2.For my 3 branches in github repo : branch1, branch2, branch3, i created three jobs in jenkins:Job1, Job2, Job3 with SCM configured as below

Source Code Management:
Repo URL: git@********/********.git
Branches to Build: refs/heads/BRANCH_NAME

Build Trigger: Build when a change is pushed to GitHub

3.关于将代码提交到我的分支:branch1.它会触发詹金斯中的所有3个作业:Job1,Job2,Job3. 注意:这是首次触发作业.

3.On committing code to my branch : branch1. It triggers all the 3 jobs in jenkins: Job1, Job2, Job3. Note:This is the first time that the jobs were triggered.

4.关于第二次提交代码的分支:branch1.它仅触发詹金斯人的Job1.

4.On committing code for the second time to branch: branch1. It triggers only Job1 in jenkins.

看起来像是第一次,所有工作都针对回购执行,而与分支无关.

It looks like first time all jobs are getting executed for the repo, irrespective of the branch.

我的jenkins设置的详细信息:Jenkins版本:1.565.1,GitHub插件:1.9.1

Details on my jenkins setup: Jenkins Version: 1.565.1, GitHub plugin: 1.9.1

感谢您提供解决此问题的帮助/指导.

Any help/guidance to solve this issue is appreciated.

仅供参考:我尝试了中列出的步骤http://kohsuke.org/2011/12/01/polling-must-die-triggering-jenkins-builds-from-a-git-hook/

推荐答案

使用follow命令制作脚本(假设您的github SO是linux)

Make a script with the follow command (assuming your github SO is linux)

curl http://yourserver/jenkins/git/notifyCommit?url=<URL of the Git repository>

将此脚本放入./git/hooks

put this script in ./git/hooks

您的詹金斯人换工作

发件人 将更改推送到GitHub时构建"

From "Build when a change is pushed to GitHub"

投票SCM"

不要在Poll SCM中创建任何时间表

Don't create any schedule in Poll SCM

这篇关于Jenkins对特定分支触发器的git commit也会为其他分支构建作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆