Run Bamboo Plan branch just once
Asked by Jozef Vandenmooter:

We have a Bamboo plan set up to create plan branches that is triggered whenever is new feature branch is created in Bitbucket (it is set up to monitor Bitbucket). We only want that plan to be executed once (when a feature branch is created) because it is used to create an sfdx scratch org.

However, the problem is that Bamboo kicks off the branch plan whenever a change is committed to the feature branch. How do we turn that off?

Thanks,

Jozef


Answers:
author: Poorna Ramchand Pemmasani
body: Hi [@Jozef Vandenmooter](/t5/user/viewprofilepage/user-id/1132796) ,

we can achieve the above requirement in the following way.

* Add the **Bitbucket Server repository triggered** trigger in the plan configuration and disable it in the Plan Configuration
* In the **Branches** under plan configuration, select the option **same as defined in the parent plan** for **Branch triggers** option.
* Configuring the plan configuration with the above steps will meet the requirements.

Please let me know if you need any other help :)

Thanks,

Poorna

comments: author: Jozef Vandenmooter
body: Works great - thanks Poorna!

Jozef


author: Steffen Opel _Utoolity_
body: I haven't actually verified this myself, but am confident that you can achieve this with the [Conditional tasks for Bamboo](https://marketplace.atlassian.com/apps/1219706/conditional-tasks-for-bamboo) app, which allows you to *Control task execution by variables* and as a use case specifically references that you can *Skip build steps in plan branches.*

Given that each branch starts with build number 1, you should be able to use the resp. [Bamboo variable](https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html#Bamboovariables-Build-specificvariables) ${bamboo.buildNumber} and skip the task if it doesn't match.  

You can find more details about this app in [@Daniel Santos](/t5/user/viewprofilepage/user-id/502125)' excellent answer to [How we can configure job with conditional tasks for bamboo Plug-in?](https://community.atlassian.com/t5/Bamboo-questions/How-we-can-configure-job-with-conditional-tasks-for-bamboo-Plug/qaq-p/1105461)

As Daniel emphasizes, the app is currently listed as *unsupported* under Atlassian Labs, but given its importance and success, and how this has been handled in the past, I'm fairly optimistic that Atlassian will at least maintain it, and maybe even promote it to a built-in Bamboo feature down the road. Please watch and vote for the following issue to further increase Atlassian's priority for an official solution regarding this highly voted feature request:

* [Conditional build step depending on value (or existence) of variable (BAM-11257)](https://jira.atlassian.com/browse/BAM-11257)  

comments: author: Jozef Vandenmooter
body: Hi Steffen,

Thanks for the reply. That looks like an awesome plugin indeed.

However, wouldn't the plan still kick off and create a log even if the Tasks are not executed? As I said, we don't want the plan to be kicked off at all anymore once the initial run created the sfdx scratch org.

Jozef


author: Daniel Santos
body: Hey [@Jozef Vandenmooter](/t5/user/viewprofilepage/user-id/1132796)  
I just want to add another idea as a second option.  

You could configure the plan branch to disable itself when it runs for the first time. For this, you would need to create a script task at the end of your build with a bash script like:

```
# If this is not the main plan branch
if [ ${bamboo.planRepository.1.branch} != '<DEFULT_SOURCE_REPOSITORY_BRANCH>' ]
  then
  # Disable this plan branch
  curl -k -u <USER>:<PASSWORD> -H "Content-type: application/json" -X DELETE <BAMBOO_URL>/rest/api/latest/plan/${bamboo.planKey}/enable
fi
```

The problem with this approach is that you will need to have credentials in your build in order to run the rest API to disable the plan. You can add them as password variables, but they would still be available in your build.  

I would stick with [@Steffen Opel _Utoolity_](/t5/user/viewprofilepage/user-id/781567)'s option if you want to avoid some of the build tasks but still want to run the build for the plan branch.  


author: Daniel Santos
body: I wrote the message above without seeing your last response... I guess it still applies to it =\]


author: Jozef Vandenmooter
body: I believe you :)

Thanks a bunch!

Jozef


author: Steffen Opel _Utoolity_
body: Hi Jozef,  

Your question about a skipped task still being logged has been implicitly answered by [@Daniel Santos](/t5/user/viewprofilepage/user-id/502125) I guess, that's indeed the case - his clever solution is spot on accordingly (see PS for an alternative that avoids the credentials issue)!  

Out of curiosity, may I ask why the logs are an issue? Incidentally the resp. extension point for a [Build Trigger Condition module](https://developer.atlassian.com/server/bamboo/build-trigger-condition-module/) actually fulfills your requirement, i.e. *"A build which fails the trigger condition will not be executed, there will be no trace of the existence of this build"* .  

However, we (Utoolity) have a backlog story for our [Automation with AWS (Bamboo)](https://marketplace.atlassian.com/apps/1216064/automation-with-aws-bamboo) app to implement such a build trigger condition that will call out to AWS Lambda, but the users we have talked about this so far always *want* to have some trace regardless, which renders the story considerably more complex for us because we'd need an audit log.  

Thanks,  
Steffen  

PS: Btw., if you happen to use AWS and do not want to make the credentials available to your build, you could use our (commercial) [Invoke Lambda Function](https://utoolity.atlassian.net/wiki/spaces/UAAWS/pages/104529951/Using+the+Invoke+Lambda+Function+action) action to interact with the Bamboo REST API remotely, which means you can securely store the required Bamboo credentials in the [Systems Manager Parameter Store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html).


author: Daniel Santos
body: Thank you, [@Steffen Opel _Utoolity_](/t5/user/viewprofilepage/user-id/781567), for adding an option to securely store the credentials.


author: Alexey Chystoprudov
body: Hello. There's much simpler solution to run only first build of new branch. It's possible to configure triggers for new plan branches. Go to Plan configuration -\> Branches. Then choose None trigger. Bamboo will create new branch, run initial build and then do nothing.

![Screenshot 2019-06-24 at 12.17.17.png](https://community.atlassian.com/t5/image/serverpage/image-id/58518i65A21E57D09B51C9/image-size/large?v=v2&px=999 "Screenshot 2019-06-24 at 12.17.17.png")

Update. My mistake. It doesn't work. Branch is created, but first build is not executed.

comments: author: Jozef Vandenmooter
body: Right - that was the first thing I tried :)