Branch merging with multiple children
Asked by Carol Serroul:

Good morning all,

We recently changed our product to support two database backends rather than just the one we had before. Previously, we merged all pull requests into our staging branch, ran a Bamboo job with our automated test suite against it and used branch merging to push the changes to the release branch if the job was successful against the staging branch.

What we'd like to do now is have the following workflow:

1. Developer merges pull request to staging branch.
2. Two jobs are triggered by that commit, one with each of the databases we support.
3. If and only if both of those jobs succeed, have the branch merging feature push the code to the release branch.

Here are some of the complications I'm facing:

1. One job takes half the time of the other as database #1 is much slower than database #2.
2. The individual jobs need to run simultaneously because we can't afford the delay of chaining them consecutively.
3. Developers can continue to commit to the staging branch while these jobs are running as we don't currently block them from doing so.

I might be missing something really obvious but I haven't found a clean way to make all these things come together nicely. I truly appreciate any advice that points me in the right direction.

Thanks!


Answers:
author: Daniel Santos
body: Hi [@Carol Serroul](/t5/user/viewprofilepage/user-id/61322)

Thanks for the structured description!

To assure I understand your scenario I still need you to share a few things with me:

1. When you say jobs I assume you are talking about plan jobs, not two different plans to run each of the jobs, is that correct?
2. When staging succeeds you want to merge the code to the release branch. Assuming your jobs are in the same plan and the Bamboo automatic merging feature is enabled, your code should be pushed to release branch only if the whole build succeeds. Can you confirm how the merge/push to release is configured in your build?
3. If you are had the merge/push to your release branch configured in your build job as a task. I guess you only need to create a new stage and move the related tasks into there. The stage will only run if both of the jobs (in the same plan) succeeds.  
   Are you using multiple stages?

I'll wait for your comments.

comments: author: Carol Serroul
body: Here is my current setup:

1. I have one plan "Product X Release" which runs on the release/5.0 branch. It has a plan branch for the staging/5.0 branch. The plan currently has one stage/job that checkouts out the code, builds the thing, runs the tests. The staging/5.0 branch/job is triggered by the repo. Both of these branches are currently only setup to run against the older of the database platforms.

As of now, I have a second plan which is configured to run the same tasks but against the release/5.0 branch, the newer database platform, and triggered by the repo. This is not ideal because if there are errors in the commits that break with the new database platform, we don't find out until after it is merged to the release branch.

2. The merge/push is configured with "Branch merging enabled" and using the Gatekeeper option with the staging plan branch.

3. I am not using multiple stages so that may be what I am missing. I am guessing that I need to setup a second stage that executes the same list of tasks but against the newer database platform. I'll poke at this option while I await your response.

Thanks!!


author: Daniel Santos
body: Hi [@Carol Serroul](/t5/user/viewprofilepage/user-id/61322)

In fact from your description, I see that what you need is another job in the same plan you already had.

As a test I suggest you the following:

1. Clone the old plan
2. In the cloned plan, create another job just to build the extra database and test it. If the tasks are similar you could even try to clone the existing old job and modify the parts you need.

Assuming both jobs are in the same stage, they will run in parallel. You don't need another plan for that. I suggest you to check out this old video about Bamboo structural concepts that will probably give you the information you need to adjust this setup:

* [Getting Started with Atlassian Bamboo - Build Structure Deep-Dive](https://youtu.be/2IRTnbzk0RQ)

Let me know your findings after that.


author: Carol Serroul
body: Thanks again Daniel! This is exactly what I needed. I couldn't confirm the solution until today because we had some broken tests in one database only that was preventing everything from being merged to the release branch. An unfortunate delay but it proved that your suggestion is exactly what we needed. After both jobs ran successfully, the code from staging was successfully merged to release. Thanks so much!!


author: Daniel Santos
body: Hi [@Carol Serroul](/t5/user/viewprofilepage/user-id/61322)

Thank you for coming back to share the good news!  
I'm happy to be able to help =\]

Have a great day!


Tags: branch