How to pass jira issue ids to bamboo build plan variable?

Konrad Gancarz
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 29, 2020

I'm looking for a way to integrate linked jira issues into build workflow.
For every bamboo build I can browse linked jira issues in GUI. How can I access this information in build scripts?

I also tried creating release from jira, manually linking issues to release and then triggering build from jira. Unfortunately still I don't see how to gather related ticket keys.

2 answers

1 vote
Daniel Brown February 19, 2020

We had to create a script in the end as a workaround. We use the ${bamboo.planRepository.revision} variable to give us the related Bitbucket commit. All of our branches in bitbucket contain the linked JIRA ticket number within the commit details returned from the Bitbucket API. Our solution connects to the Bitbucket API and uses the above build variable to return all of the commit details, once returned we grep the response to identify the JIRA ticket number linked with the commit. You'll have to update the <JIRA_ticket_prefix> below to use your project's ticket prefix, in our case this is followed by 4 numbers at the moment, but if you have more you'll have to update the {4} below too.

 

Once we have the JIRA ticket number returned, we then save it to a file located: /var/lib/bamboo-home/artifacts/variable_injection but again, you can change this to whatever you wish.

 

#!/bin/bash
COMMIT=${bamboo.planRepository.revision}
BITBUCKET_CLIENT_ID=<enter_client_id>
BITBUCKET_CLIENT_SECRET=<enter_bitbucket_secret_key>
BITBUCKET_USERNAME=<enter_bitbucket_username>
BITBUCKET_PASSWORD=<enter_bitbucket_password>

OUTPUT_DIRECTORY=/var/lib/bamboo-home/artifacts

# Sign in to Bitbucket and get a token
ACCESS_TOKEN=$(curl -s -X POST -u "$BITBUCKET_CLIENT_ID:$BITBUCKET_CLIENT_SECRET" https://bitbucket.org/site/oauth2/access_token -d grant_type=password -d username=$BITBUCKET_USERNAME -d password=$BITBUCKET_PASSWORD | jq '.access_token')

# Get the JIRA ticket number from the commit
TICKET=$(curl -s https://api.bitbucket.org/2.0/repositories/<company_name>/<repo>/commit/$COMMIT?access_token=$ACCESS_TOKEN | jq '.rendered.message.raw' | grep -P '(<JIRA_ticket_prefix>.[0-9]{4})' -o | uniq)

echo "** Found JIRA ticket: $TICKET from commit: $COMMIT"

# Write the feature tag to a file for Bamboo
if [ -d $OUTPUT_DIRECTORY ]
then
echo "jiraticket=$TICKET" > "$OUTPUT_DIRECTORY/variable_injection"
else
echo "ERR - INVALID FILE LOCATION"
fi

 

Once all of this has finished, you should have a JIRA ticket number stored in a file /var/lib/bamboo-home/artifacts/variable_injection 

Next, you can use the bamboo Inject Variable task to read the file ../../../artifacts/variable_injection which contains your JIRA ticket number and creates a variable of ${bamboo.inject.jiraticket} to then be used elsewhere in your build.

 

It seems pretty long-winded, but it's the only thing we could think of for the time being as a workaround until Bamboo creates its own JIRA ticket variable.

 

Hope this helps people,

Dan

Darrin Khan July 1, 2020

Hey Dan,

Thanks for sharing.

 

Answers my query also.

 

Cheers,

Darrin

0 votes
Jeyanthan I
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 6, 2020

Hey @Konrad Gancarz ,

If I understand correctly, you wanted to refer the Jira isssue ID in Bamboo builds. I was going to suggest one of the default Bamboo variables for Jira. I then realised there is no variable to collect Issue ID that triggered the build.

Available JIRA variables (as of Bamboo 6.10.4) are as follows:

  • ${bamboo.jira.baseUrl} - The URL of your JIRA application server.
  • ${bamboo.jira.projectKey} - The key of the triggering JIRA application project.
  • ${bamboo.jira.projectName} - The name of the triggering JIRA application project.
  • ${bamboo.jira.username} - The username of the user who triggered the release build.
  • ${bamboo.jira.version} - The release version of the triggering Jira application project.

I have therefore created a feature request on your behalf. Please upvote and comment.

As a workaround, I propose

  1. Create a script Task within the plan.
  2. In the script, make a REST call to Jira to fetch the corresponding Issue ID.

References to REST documentation: 

Hope that helps!

Cheers,
Jey

Daniel Brown February 7, 2020

Hi Jey,

How would we make a REST call to Jira to fetch the corresponding issue ID when the details aren't stored in Bamboo? Looking at the Jira REST API docs, we'd need to provide the issue ID in the call?

Please could you give an example?

Thanks,

Dan

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events