如果从 bitbucket 触发时发生更改,如何让 Jenkins 仅构建功能分支 [英] How can I make Jenkins only build feature branches if they have changed when triggering from bitbucket

查看:24
本文介绍了如果从 bitbucket 触发时发生更改,如何让 Jenkins 仅构建功能分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Jenkins 工作,它构建与origin/feature/**"匹配的分支.

I have a Jenkins job that builds branches that match "origin/feature/**".

只要通过存储库挂钩 (https://confluence.atlassian.com/display/BITBUCKET/Jenkins+hook+management).

Bitbucket triggers the job to build whenever there are changes to the repository via a repository hook (https://confluence.atlassian.com/display/BITBUCKET/Jenkins+hook+management).

只要功能分支发生更改,此功能就可以正常工作,作业会识别分支已更改并构建它.

This works fine whenever there is a change on a feature branch, the job recognizes that the branch has changed and builds it.

但是,当提交到非功能分支(例如合并到开发或主控)时,bitbucket 仍会触发该作业.任何功能分支都没有更改,因此它只是再次构建最后构建的功能分支.

However, when there is a commit to a non-feature branch (eg. a merge to develop or master) bitbucket still triggers the job. There are no changes to any of the feature branches so it just builds the last built feature branch again.

有办法控制吗?

推荐答案

经过一番研究,我终于找到了一个好的解决方案:

After some research I found a good solution finally:

  • 在您的 Jenkins 上安装 Bitbucket 插件
  • 将普通的 Post 作为 Hook 添加到您的 Bitbucket 存储库(Settings -> Hooks)并使用以下网址:
  • Install Bitbucket Plugin at your Jenkins
  • Add a normal Post as Hook to your Bitbucket repository (Settings -> Hooks) and use following url:

https://YOUR.JENKINS.SERVER:PORT/bitbucket-hook/

https://YOUR.JENKINS.SERVER:PORT/bitbucket-hook/

  • 如下配置您的 Jenkins 项目:
    • 构建触发器下启用在将更改推送到 BitBucket 时构建
    • 源代码管理下选择GIT;输入您的凭据并定义要构建的分支(如 **feature/*)
      • Configure your Jenkins project as follows:
        • under build trigger enable Build when a change is pushed to BitBucket
        • under Source Code Management select GIT; enter your credentials and define Branches to build (like **feature/*)
        • 这样我就有了三个构建项目,一个用于所有功能,一个用于开发,一个用于发布分支.

          By this way I have three build projects, one for all features, one for develop and one for release branch.

          这篇关于如果从 bitbucket 触发时发生更改,如何让 Jenkins 仅构建功能分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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