Trigger a Bamboo plan build from an issue

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.

We're assuming that:

  • you just want to trigger a CI job, period; this job may be totally unrelated to the issue from where you triggered it
  • 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.

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}


Automation configuration

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

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

  • the Webhook URL provided above follows this syntax:
    • <bamboo_base_url>/rest/api/latest/queue/${projectKey}-${planKey}
  • 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)
    default&ExecuteAllStages=true
  • 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 using your Bamboo credentials


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


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

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

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.

We're assuming that:

  • you just want to trigger a CI job, period; this job may be totally unrelated to the issue from where you triggered it
  • the results will be submitted back to Xray, if the project is configured to do so in Bamboo


Bamboo configuration

The project itself is a normal one; the only two things relevant to mention are:

  • 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.

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

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}


Automation configuration

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

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

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

  • the Webhook URL provided above follows this syntax:
    • <bamboo_base_url>/rest/api/latest/queue/${projectKey}-${planKey}
  • 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)
    default&ExecuteAllStages=true&bamboo.TESTPLAN={{issue.key}}
  • 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 using your Bamboo credentials


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


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


References