Search code examples
javamavencontinuous-integrationbamboogit-flow

Bamboo build plan on branches but not on develop (aka conditional build)


This is an attempt to implement a conditional build across branches, impossible by default because of BAM-11257, open since 2012, still pending.

Context:

  • Bamboo 5.10.3
  • Gitflow branching strategy applied
  • We would like to have a certain behavior on feature branches, a different behavior on release and hotfix branches, and a third different behavior on the develop branch

Implemented (not working) approach:

  • Three different build plan
  • The first provides a regex in the "Branches" tab of the build plan ("Create plan branches for matching new branches) to only match feature and bugfix branches ((?=(feature.*|bugfix.*)).*$). Then it provides the desired behavior in its stages and jobs
  • The second one as above configured for release and hotfix branches ((?=(hotfix.*|release.*)).*$), then with its own behavior in stages
  • The third has the "Do not create plan branches" in its "Branches" control, that is, no branching, only for develop.

This works fine, each branch has its own build plan based on the desired behavior. However, when merging any branch into develop, the three build plan start in parallel, because the three of them have develop in their "Repositories" as original branch entry.

Question: how could this side effect be avoided? How could we specify a build plan for certain branch types only and not also for the original branch (in this case develop)?


I understand Bamboo needs an origin from which cloning new build plan for its branches according to a certain strategy (the regex), but how can we block it to run the build plan for the original branch as well? Or, can we define a build plan for a branch type independently than its origin and based on a dynamic name (e.g. feature-something, feature-bob)?

(On this last point: in "Repository" we can specify a branch as origin, but that's a static value, we cannot put a regex there, which would fix the overall issue, I suppose)


Solution

  • I've been facing similar issues. The only workaround I found was to stop using "linked repositories". Don't know if you're familiar with this but you can either use a "linked repository" which is available to all Build Plans or you can create one specifically for your Plan. To solve my issue, I had to add a repository of type "Git" (even though we use GitHub). This allowed me to leave the "branch" field empty, thereby fixing my issue.

    EDIT In fact I had to specify a "wrong" branch name in this field to get it working...

    Hope this helps. Simon