---
title: "Trigger a Bamboo plan build"
canonical: "https://docs.getxray.app/space/XRAYCLOUD/44565656/Trigger%20a%20Bamboo%20plan%20build"
format: markdown
---
> Macro (toc)

# Trigger a Bamboo plan build from an issue

<span style="color: #000000">In this very simple scenario, we'll implement a rule, triggered manually, that will trigger a Bamboo plan build. The action will be available from the "Automation" panel, in all issues of the selected project.</span>

<span style="color: #000000">We're assuming that:</span>

- <span style="color: #000000">you just want to trigger a CI job, period; this job may be totally unrelated to the issue from where you triggered it</span>
- what the CI job will do, including if it will report the results back to Xray or not, is not relevant


##  Bamboo configuration

In a Bamboo Plan Configuration we will use the Script task to import the results back to Xray. We have defined internal Bamboo variables for the *CLIENT_ID*, *CLIENT_SECRET*, that are required for authentication and the *TESTPLAN* to associate on the Xray side.

![image](media://d516329f-8616-4d12-8811-1a7344a72e0a)

<details>
<summary>Expand</summary>

```shell
token=$(curl -H "Content-Type: application/json" -X POST --data '{ "client_id": "${bamboo.CLIENT_ID}","client_secret": "${bamboo.CLIENT_SECRET}" }' https://xray.cloud.getxray.app/api/v1/authenticate| tr -d '"');
curl -H "Content-Type: text/xml" -X POST -H "Authorization: Bearer $token"  --data @"/home/jira/bamboo-home/xml-data/build-dir/XRAY-JAV-JOB1/java-junit-Bookstore/target/surefire-reports/TEST-com.xpand.java.BookstoreTest.xml" https://xray.cloud.getxray.app/api/v1/import/execution/junit?projectKey=XT&testPlanKey=${bamboo.TESTPLAN}
```
</details>


## Automation configuration

1. create a new rule and define the "When" (i.e. when it to should be triggered), to be "Manually triggered"

![image](media://90e5ad86-10df-49e7-ba21-ffbc8c96fbbb)

2. define an action (i.e. the "Then") as "Send web request" and configure it as follows

![image](media://b9898c2f-07a2-4a5f-88ec-b07cd96c2cd8)

- the Webhook URL provided above follows this syntax:
  - <bamboo_base_url><span style="color: #003366">/rest/api/latest/queue/${projectKey}-${planKey}</span>
- the Webhook HTTP POST body content, defined in the "Custom data" field, will be used to identify the stages to run and other parameters
  **custom data (i.e. HTTP body content)**
- besides the "Content-Type" header that should be "application/x-www-form-urlencoded", define also an "Authorization" header having the value "Basic <auth>", where  the base64 encoded <auth> can be [generated](https://www.blitter.se/utils/basic-authentication-header-generator/) using your Bamboo credentials


After publishing the rule, you can go to the screen of an issue and trigger the Bamboo plan build.

![image](media://ae70810b-9e73-48fc-9d58-8d65a8c5a3e2)


In this case, since Bamboo was configured to report results back to Xray, a new Test Execution would be created in Jira/Xray.

![image](media://c48aadad-8cab-41d9-8fc6-1788c4a07785)

# Trigger a Bamboo plan build from a Test Plan and report the results back to it

<span style="color: #000000">In this simple scenario, we'll implement a rule, triggered manually, that will trigger a Bamboo's plan build. The action will be available from the "Automation" panel, for all Test Plan issues of the selected project.</span>

<span style="color: #000000">We're assuming that:</span>

- <span style="color: #000000">you just want to trigger a CI job, period; this job may be totally unrelated to the issue from where you triggered it</span>
- <span style="color: #172b4d">the results will be submitted back to Xray, if the project is configured to do so in Bamboo</span>


## Bamboo configuration

<span style="color: #172b4d">The project itself is a normal one; the only two things relevant to mention are:</span>

- <span style="color: #172b4d"> that this project is a parameterized one, so it receives a TESTPLAN variable, that in our case will be coming from Jira and that we have added a step to import the results back to Xray.</span>

![image](media://62da536c-7013-4b7e-93d1-fd0056511a0e)

- For authentication we use internal Bamboo variables to define the *CLIENT_ID*, *CLIENT_SECRET* and the *TESTPLAN* to associate on the Xray side.

![image](media://d516329f-8616-4d12-8811-1a7344a72e0a)

<details>
<summary>Expand</summary>

```shell
token=$(curl -H "Content-Type: application/json" -X POST --data '{ "client_id": "${bamboo.CLIENT_ID}","client_secret": "${bamboo.CLIENT_SECRET}" }' https://xray.cloud.getxray.app/api/v1/authenticate| tr -d '"');
curl -H "Content-Type: text/xml" -X POST -H "Authorization: Bearer $token"  --data @"/home/jira/bamboo-home/xml-data/build-dir/XRAY-JAV-JOB1/java-junit-Bookstore/target/surefire-reports/TEST-com.xpand.java.BookstoreTest.xml" https://xray.cloud.getxray.app/api/v1/import/execution/junit?projectKey=XT&testPlanKey=${bamboo.TESTPLAN}
```
</details>


## Automation configuration

1. create a new rule and define the "When" (i.e. when it to should be triggered ), to be "Manually triggered"

![image](media://93a1ffaf-2a31-421a-9be6-c0e5bbd33133)

2. define the condition so that this rule can only be executed from Test Plan issue; this can also be done on the previous step

![image](media://9ad0f289-8bfa-447c-9f3d-5f597f948e61)

3. define an action (i.e. the "Then") as "Send web request" and configure it as follows

![image](media://e72f91be-5e1f-4398-bbee-9ec2bcc448b4)

- the Webhook URL provided above follows this syntax:
  - <bamboo_base_url><span style="color: #003366">/rest/api/latest/queue/${projectKey}-${planKey}</span>
- the Webhook HTTP POST body content, defined in the "Custom data" field, will be used to identify the stages to run and other parameters
  **custom data (i.e. HTTP body content)**
- besides the "Content-Type" header that should be "application/x-www-form-urlencoded", define also an "Authorization" header having the value "Basic <auth>", where  the base64 encoded <auth> can be [generated](https://www.blitter.se/utils/basic-authentication-header-generator/) using your Bamboo credentials


After publishing the rule, you can go to the screen of an issue and trigger the Bamboo plan.

![image](media://05eba80e-5ba8-4bcf-80ef-4432f41b1877)


In this case, since Bamboo was configured to report results back to Xray, a new Test Execution would be created and linked back to the source Test Plan where the automation was triggered from

![image](media://89b0995a-ffdd-4fb7-9dae-66ac15347c02)

![image](media://778ee230-8f2a-4e01-862b-73c2336d913c)


# References

- [GraphQL to JSON Body Converter](https://datafetcher.com/graphql-json-body-converter)
- [Jira Automation in Jira Cloud](https://support.atlassian.com/cloud-automation/docs/jira-cloud-automation/)
  - [Jira smart values - issues](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-issues/)
  - [Jira smart values - lists](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-lists/)
  - [Jira smart values - text fields](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/)
  - [Jira smart values - users](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-users/)
  - [Jira smart values - conditional logic](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-conditional-logic/)
  - [Jira smart values - JSON functions](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-json-functions/)