git - 特定分支的 Jenkins git commit 也会触发其他分支的构建作业

标签 git github jenkins

我们有一个内部企业 Github 存储库,我有多个功能分支。 我在触发特定分支上的构建时遇到问题。 我已经为每个功能分支配置了作业。一个功能分支有一个 Jenkins 工作。 我第一次提交代码时,它还会触发其他分支的作业构建。

重现问题的步骤:

1.我们有一个企业内部的Github。对于我的 repo,我为 github 设置了 webhook,如下所示

 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 配置如下

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。它会触发 jenkins 中的所有 3 个作业:Job1、Job2、Job3。 注意:这是第一次触发作业。

4.关于第二次提交代码到分支:branch1。它只触发 jenkins 中的 Job1。

看起来第一次所有作业都为 repo 执行,无论分支如何。

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

感谢任何解决此问题的帮助/指导。

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

最佳答案

使用以下命令制作脚本(假设你的github SO是linux)

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

把这个脚本放在./git/hooks

在你的 jenkins 工作中改变 <​​/p>

来自 “将更改推送到 GitHub 时构建”

“投票 SCM”

不要在 Poll SCM 中创建任何计划

关于git - 特定分支的 Jenkins git commit 也会触发其他分支的构建作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31886963/

相关文章:

windows - 从 Git 推送和 pull 后,目录符号链接(symbolic link)更改为文件符号链接(symbolic link)

git - 取消了一个git-clone,下载的文件在哪里?

git - TortoiseGit 保存用户身份验证/凭证

django - github自动更新评论是如何工作的?

maven - Jenkins maven项目构建失败

git - GitHub 上 pull request 中的分支名称

git - GitLab 是否通过 git-annex 或其他方式支持大文件?

jquery - Github 将多个文件合并成一个压缩的主文件

angularjs - NPM 适用于命令行,但不适用于 Jenkins

jenkins - 如何识别在 Jenkins 上创建特定工作的用户?