Skip to main content

Add Jira Automation Rule to trigger Bamboo build


Add Jira Automation Rule to trigger Bamboo build

To trigger the build in Bamboo when we release a version in Jira, we want to setup a Jira Automation rule. It used to be a standard trigger, but Bamboo discontinuedopen in new window that standard trigger, so we are going to accomplish the same thing with a Jira Automation rule.

Download Automation rule

The quickest way is to download a pre-configured automation rule in the attached XML file here

Instructions to import an automation rule are hereopen in new window

When we import the rule:

  • Restrict the rule to just the Jira project with our development.
  • Don't import the owner of the rule

If we prefer a manual setup, make sure that the URL for the Web Request action looks as follows (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}}
&bamboo.triggerReason.jiraProjectName={{version.project.name.urlEncode}}
&bamboo.triggerReason.jiraUsername={{userName.urlEncode}}
&bamboo.triggerReason.jiraUserDisplayName={{userFullName.urlEncode}}
&bamboo.customPlanTriggerKey=com.fouroaksconsulting.tools.jdabambooplugin:jiraReleaseWmsPlanTrigger
&bamboo.customTriggerReasonKey=com.fouroaksconsulting.tools.jdabambooplugin:jiraReleaseWmsTriggerReason
&bamboo.triggerReason.jiraBaseUrl={{baseUrl.urlEncode}}

Set Variables

After importing the automation rule, open the rule in Project Settings -> Automation and change the following variables:

Jira Automation Variables to changeJira Automation Variables to change

See the chapters below on how to do this.

bambooBaseURL

The bambooBaseURL is the URL how Jira Cloud can access Bamboo. This is usually through a proxy server and should be setup as part of the initial setup instructions here.

For example, for a connection using ngrok as the proxy method, the bambooBaseURL value could be:

https://fouroaksconsulting.ngrok.io

Jira Automation bambooBaseURLJira Automation bambooBaseURL

bambooProjectKey

The bamboo project key refers to the unique ID of the project for the build plan that we want to trigger. Unfortunately, this key is not not visible from regular screens in Bamboo, so we have to dig a bit deeper. Follow the steps below.

  1. in Bamboo, go to the build plan we want to run when we release a version from Jira
  2. under Actions, click on 'Configure Plan'
  3. again under Actions, click 'View Plan as Yaml'
  4. In the YAML file, look up this section (at the top of the document):
version: 2
plan:
  project-key: WMSTES
  key: W1
  name: WMS-TEST 1
  description: Build artifacts for a given Jira release
get the plan key the same way and look for this section:

The value after project-key is the value to fill in for the bambooProjectKey variable.

Example: Jira Automation bambooProjectKeyJira Automation bambooProjectKey

bambooPlanKey

Similar to the bambooProjectKey, the bambooPlanKey is not visible in regular bamboo screens. We need to use the same YAML file as the one exported above and find the same section at the top:

version: 2
plan:
  project-key: WMSTES
  key: W1
  name: WMS-TEST 1
  description: Build artifacts for a given Jira release
get the plan key the same way and look for this section:

The value for key is the value for the the bambooPlanKey

Jira Automation bambooPlanKeyJira Automation bambooPlanKey

auth

The auth variable is used in the header for the HTTP request as follows:

Authorization: Bearer {{auth}}

Effectively, the auth variable is an API token that we generate in Bamboo.

This documentopen in new window describes how to create an API token in Bamboo. Look for the section 'Creating a token'. For our token, we want 'Triggering Permissions'.

Put the token in the auth variable in Jira Automation.

Info

putting the API token in automation rules may pose a security weakness because the token is visible for administrators who can edit Jira Automation rules. This post describes a method to mitigate this. open in new window

Last update:
Contributors: Pieter Hartog