简体   繁体   English

Jenkins git提交特定的分支触发器也为其他分支构建作业

[英]Jenkins git commit for specific branch triggers build jobs for other branches too

We have a internal enterprise Github repo, and i have multiple feature branches. 我们有一个内部企业Github repo,我有多个功能分支。 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. 一个功能分支有一个jenkins工作。 The first time i commit a code, it also triggers builds for jobs with other branches. 我第一次提交代码时,它还触发了与其他分支的作业的构建。

Steps to reproduce the problem: 重现问题的步骤:

1.We have a internal Github for enterprise. 1.我们有一个企业内部Github。 For my repo, i have setup webhook for github as below 对于我的回购,我已经为github设置了webhook,如下所示

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

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 2.对于github repo中的3个分支:branch1,branch2,branch3,我在jenkins中创建了三个作业:Job1,Job2,Job3,SCM配置如下

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.On committing code to my branch : branch1. 3.将代码提交给我的分支:branch1。 It triggers all the 3 jobs in jenkins: Job1, Job2, Job3. 它会触发jenkins中的所有3个作业:Job1,Job2,Job3。 Note:This is the first time that the jobs were triggered. 注意:这是第一次触发作业。

4.On committing code for the second time to branch: branch1. 4.On代码第二次提交分支:branch1。 It triggers only Job1 in jenkins. 它只触发jenkins中的Job1。

It looks like first time all jobs are getting executed for the repo, irrespective of the branch. 看起来第一次所有工作都要为回购执行,无论分支如何。

Details on my jenkins setup: Jenkins Version: 1.565.1, GitHub plugin: 1.9.1 关于我的jenkins设置的详细信息:Jenkins版本:1.565.1,GitHub插件:1.9.1

Any help/guidance to solve this issue is appreciated. 任何有助于解决此问题的帮助/指导都表示赞赏。

FYI: I tried steps listed http://kohsuke.org/2011/12/01/polling-must-die-triggering-jenkins-builds-from-a-git-hook/ 仅供参考:我尝试过上面列出的步骤http://kohsuke.org/2011/12/01/polling-must-die-triggering-jenkins-builds-from-a-git-hook/

Make a script with the follow command (assuming your github SO is linux) 使用follow命令创建一个脚本(假设你的github SO是linux)

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

put this script in ./git/hooks 把这个脚本放在./git/hooks中

In your jenkins jobs change 在你的詹金斯工作变化

From "Build when a change is pushed to GitHub" “将更改推送到GitHub时构建”

To "Poll SCM" “轮询SCM”

Don't create any schedule in Poll SCM 不要在Poll SCM中创建任何计划

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM