How to trigger a branch after successful build of another branch with a different name

Still need help?

The Atlassian Community is here for you.

Ask the community

Purpose

It's currently possible – if using Bamboo version 4.2+ – to set up plan dependencies and have a branch triggered after a successful run of a branch with the same name. Polling the branch for changes every 30 seconds is a pretty common option. Other trigger types are available under Plan Configuration > Branches tab and you can also modify notifications and/or variables for each branch. Refer to this blog post for additional details:  Branch Out with Bamboo 4.2! This is not possible however, when the branch names do not match. 

 

Solution

An example using a local instance:

  1. "SamplePlan" and "NewGitBasedPlan" are two separate plans under two separate projects that are using the same main Git repository.
  2. Branches are: "FirstBranch", "SecondBranch", "ThirdBranch", "FourthBranch" and "FifthBranch".
  3. In "NewGitBasedPlan" 
    1. I select "FourthBranch", check the "Change Trigger" checkbox under the "Branch Details" tab and select "Polling the Repository for Changes". I also edited the "Polling Frequency" value to 30 seconds.
    2. I then switched to the "Source Repository" tab for this branch, selected "Override the plan's default repository" checkbox and in the "Branch" box, added the name of the branch that I want this branch to be triggered after. Ex.: if I want this branch to be triggered after commits/changes to "FirstBranch" of my "SamplePlan" plan, I add "FirstBranch" in this field.
  4. Now, if there are any changes to "FirstBranch", "FourthBranch" will check my Git repo for this branch, polls after 30 seconds and builds.

 

If the dependent build needs to fire AFTER the parent build finishes,  set a 'quiet period' for the amount of time it takes for the parent build to complete (about 20 second) and only if parent build succeeds.

Also, the above solution works only if code is committed to the repo. Manual executions of the parent build will not cause the dependent build to fire because the repo needs to be updated in order for the polling to recognize a change. To make this work we can use a Bamboo REST API. Specifically, we'll add a script task as the last task in our stage with a command similar to the following:

admin:admin is the <username>:<password> of the Bamboo user and TOT-NEW1 is the plan branch key of the child branch we want to trigger.

curl -X POST --user admin:admin "http://localhost:8085/bamboo530/rest/api/latest/queue/TOT-NEW1?executeAllStages=true"

 

You can either set this stage as manual or have it run after the default stage (or other stages you might have) automatically. This stage can also have a source code checkout task before calling the REST API script using the parent branch. The repository can be added under the main repositories tab of the plan in order for it to be available to select in this task.

Last modified on Aug 18, 2016

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.