How to trigger a Bamboo build from Jira Cloud

14 november 2022
In Jira Server and Data Center, you have the option to trigger a build in Bamboo when releasing a version, the “Build & Release“-functionality as described here. Atlassian removed this functionality for Jira Cloud but did not document a good alternative solution to replace this functionality. We at TMC ALM did some research together with Atlassian Support and here it is!

In Jira Server and Data Center, you have the option to trigger a build in Bamboo when releasing a version, the “Build & Release“-functionality as described here. Atlassian removed this functionality for Jira Cloud but did not document a good alternative solution to replace this functionality. We at TMC ALM did some research together with Atlassian Support and here it is!

Jira Automation

We will have to use Jira Automation for this, so the replacement functionality will not be as flexible as it was originally implemented. For example, you will not be able to select the repository and branch for the build. It will use the repository and branch as defined in the Bamboo plan you are triggering to start building.

Defining the trigger

In Jira Automation we send a web request (action) to Bamboo when a version is released (trigger) in Jira Cloud.

The Version released trigger provides the option to match the version with a regular expression e.g. 0.[0-9]*-SNAPSHOT. Use this to trigger the build of a specific plan when releasing a specific version.

Setting the variables required

We always like to create easily reusable automation rules. That’s why we start off by defining all the variables we need for the rule. In this case, we add the Create variable action for the following variables:

  1. Bamboo’s base URL: {{bambooBaseURL}}, e.g. https://bamboo.company.com
  2. The Bamboo Plan Key: {{bambooPlanKey}}, e.g. PLANKEY
  3. The Bamboo Project Key of the project the Plan is part of: {{bambooProjectKey}}, e.g. PROJECTKEY
  4. The Base64 encoded authentication credentials for the user who will execute the build in Bamboo: {{auth}}, e.g. YmFtYm9vVXNlck5hbWU6YmFtYm9vVXNlclBhc3N3b3Jk.
    More info on creating Base64 encoded credentials can be found here.

Sending the web request

Now, that we’ve got our trigger defined and the required variables set, we can add the Send web request action to the automation rule, so that Bamboo will be triggered to start building the release.

First we need to define the Web request URL. This is where it gets interesting because we need to use an URL with undocumented query parameters for this. Additionally, we’ll be using the variables we created earlier and some smart values to inform Bamboo about the release details, just like the original “Build & Release“-functionality does. The query parameters will also make sure you are not triggering a so-called Manual build, but a Release build.

Do not worry about the undocumented query parameters, as the original “Build & Release“-functionality relies on this as well.

The Web request URL should look like this, but without the line breaks:

{{bambooBaseUrl}}/rest/api/latest/queue/{{bambooProjectKey}}-{{bambooPlanKey}}
?bamboo.triggerReason.jiraProjectKey={{version.project.key.urlEncode}}
&bamboo.triggerReason.jiraVersion={{version.name.urlEncode}}
&bamboo.triggerReason.jiraVersionId={{version.id.urlEncode}}
&bamboo.triggerReason.jiraProjectName={{version.project.name.urlEncode}}
&bamboo.triggerReason.jiraUsername={{initiator.accountId.urlEncode}}
&bamboo.triggerReason.jiraUserDisplayName={{initiator.displayName.urlEncode}}
&bamboo.customPlanTriggerKey=com.atlassian.bamboo.plugin.jira:jiraReleasePlanTrigger
&bamboo.customTriggerReasonKey=com.atlassian.bamboo.plugin.jira:jiraReleaseTriggerReason
&bamboo.triggerReason.jiraBaseUrl={{baseUrl.urlEncode}}

Additionally, you need to provide the following details:

  • Headers:
    • Name: Authorization
    • Value: Basic {{auth}}
  • HTTP method: POST
  • Web request body: Custom data
  • Custom data: {}
    Bamboo doesn’t accept an empty body for the Web request URL
  • Wait for response: Check the option Delay execution of subsequent rule actions until we've received a response for this web request

That’s it! Your automation should look something like this:

In Bamboo, this will give you the exact same result as the original Build & Release functionality would:

Update version description with build information

Optionally, you could update the description of the version that was released and for which the build was triggered with the build information from the web request response.

The web request response can be accessed using the smart value {{webResponse.body}}. The build details that can be retrieved are as follows:

  • {{webResponse.body.planKey}} = Bamboo project key and plan key
  • {{webResponse.body.buildNumber}} = Build number in Bamboo
  • {{webResponse.body.buildResultKey}} = Key of the build result in Bamboo
  • {{webResponse.body.triggerReason}} = Event that triggered the build in Bamboo; in this case this will always be Jira Release
  • {{webResponse.body.link.href}} = link to build in Bamboo

To update the release, a Send web request action has to be added. Use the “Update version” Web request URL for this. More information about this Jira REST API endpoint can be found here: The Jira Cloud Platform REST API
Use the smart value {{version.id.urlEncode}} to specify the version in question in the Web Request URL.

Need help?

If you still have any questions regarding triggering Bamboo builds from Jira Cloud – or any other – Atlassian topic? The certified experts of TMC ALM are happy to help you with all of your questions, requests, or remarks. Feel free to reach out to us via our contact page to start the conversation.