How to override branch builds strategy from single yaml spec?
Asked by jodyfanning:

I asked this under <https://community.atlassian.com/t5/Bamboo-questions/Different-merging-strategy-for-release-branches-in-Bamboo-Specs/qaq-p/1469251>, but didn't get any answer, so I'll ask this again as a specific question.

How can I define an override for branches so that specifically name branches get a different branch plan creation/merge strategy than the default?

I have a generic plan in Bamboo Yaml specs with normal development branches being created by pull-request with a specific merge strategy that is used for running tests. But we also have release branches that are branched periodically and track a production release. These release branches are created as a specifically named branch and **never** merge to master. I would like Bamboo to automatically create branch plans for these as well and to run the tests, only without the merge to master. If this was a manual Bamboo job then I could live with the default option, and someone can manually create a new release branch with *different* merge strategy.

Now that we have Yaml specs we cannot continue with this manual process for release branches given that having a spec disables creating branch plans.

I see that I can have branch overrides, and I have implemented that according to [how I understand it should be](https://docs.atlassian.com/bamboo-specs-docs/7.2.5/specs.html?yaml#overriding-branch-settings-using-bamboo-specs), but it doesn't do anything.

```
branches:
  create: for-pull-request
  delete:
    after-deleted-days: 0
    after-inactive-days: 10
  integration:
    push-on-success: false
    merge-from: core-build
  link-to-jira: true
branch-overrides:
  -
    ^test_.*$:
      branch-config:
        create:
          for-new-branch: ^test_.*$
        delete:
          after-deleted-days: 0
          after-inactive-days: 10
        link-to-jira: true
```

I create a branch in git matching the regex (i.e test_mybranch), but I still don't get any branch appearing automatically. The only branches that appear are those coming from pull-requests.


Answers:
author: jodyfanning
body: In the end I just went with two completely separate plans in Bamboo since this seems to be impossible to resolve in a single plan. One plan follows branches created by Pull Request. The other plan follows branches created by name regex. They are both based on common YAML files for all of the jobs and tasks, the difference between the two being the branch management.

Unfortunately now it means that developers, etc now have two different plans to follow in Bamboo.


author: jodyfanning
body: Actually I think I am barking up completely the wrong tree here since I now realise that the branch-overrides *only* allow overriding the branch-config. But now from the documentation it is completely unclear what the relationship is between the main bamboo specs and any particular branch. So just what does branch-config, actually even do?  

I want to provide a single bamboo spec file in master. And any time a developer creates a branch, I want that this bamboo spec already contains all the rules about what those branches should do without requiring any further action.

**But nothing works.**

Every single variation that I can think of usually results in either a spec that cannot be parsed, or an error that says things like

```
Document structure is incorrect: Found following unused properties: branch-config / create, branch-config / delete, branch-config / link-to-jira.

Every property must have a correct key recognizable by Bamboo and must be used as part of the configuration in the current YAML document. Common sources of these problems are typos in properties keys, unused jobs, and mixing a plan and its permissions configuration in one YAML document.
```

Surely there is some way to override the default branch behaviour based on the branch name?


Tags: spec

yaml