分享

Can we change status of jira ticket on bamboo deploy. Not on bamboo build

 bananarlily 2016-06-02

Short answer:

  1. Install 'Pre-Post Build Command Runner' on Bamboo (https://marketplace./plugins/com.sysbliss.bamboo.plugins.prepost-build-command/server/overview)
  2. Add two stages to your build: a 'build stage and a 'deployment' stage
  3. Add a job to the 'build' stage with tasks that package the files you want to deploy to an artifact
  4. Add a job to the 'deployment' stage with tasks that send the artifact to your server of choice and unpack it there
  5. Open JIRA, go to your workflows, open the desired workflow in text mode and note/write down the respective transition id (you can find it in brackets to the right of the transition name)

Assuming that your build is triggered by a commit to your repository with a respective JIRA issue key in commit message (e.g. JIRA-123):

  1. Write a script that polls your repository, gets the message of the last commit in a desired branch, extracts the respective JIRA issue key from it and writes it down in a .txt file. Save it on your Bamboo server with a distinct name.
  2. Write a script that reads your .txt file, extracts issue key from there, sends a POST request to JIRA API with respective transition id and issue key. Save it on your Bamboo server with a distinct name.
  3. Go to your Bamboo build configuration, open the 'build' stage, open the 'miscellaneous' tab, enter the location of the first script in the 'Command' line of the 'Pre Build Commands' section, tick 'Run on Bamboo Server' and press 'Save'.
  4. Go to your Bamboo build configuration, open the 'deployment' stage, open the 'miscellaneous' tab, enter the location of the second script in the 'Success Command' line of the 'Post Build Commands' section, tick 'Run on Bamboo Server' and press 'Save'.
  5. Make sure both Bamboo and JIRA are authenticated to mess with one another. You can set up the credentials in JIRA and Bamboo settings under 'Application links'.

It took me about 15 hours to figure it out. The in-built 'Builds workflow' didn't transition my issue statuses and the answer to my question to Atlassian support is still pending.

Some hints (assuming your Bamboo runs on Linux):

  1. Installing 'Pre-Post Build Command Runner'

    a. Log onto your Bamboo server and navigate to Bamboo plugins directory:

    cd ~/atlassian-bamboo-X.X.X/atlassian-bamboo/WEB-INF/lib    
    

    b. Download 'Pre-Post Build Command Runner':

    wget https://marketplace-cdn./files/artifact/3f77baa2-8624-4a80-9b5d-1f6029fc1133/prepost-build-command-5.6.3.jar
    

    c. Restart Bamboo

    cd ~/atlassian-bamboo-5.9.7/bin
    ./stop-bamboo.sh
    ./start-bamboo.sh
    

    d. Go to 'Bamboo Administration/Add-ons' and click 'Pre-Post Build Command Runner' under 'User-installed add-ons' e. Check that all its modules are enabled (it should say 'X of X modules enabled')

  2. Configuring scripts

    a. Install jq

    sudo apt-get install jq
    

    b. Script for polling your repository (assuming it's Bitbucket)

    #!/bin/bash
    
    message=$(curl --user <bitbucket-username>:<bitbucket-password> https:///api/1.0/repositories/<bitbucket-username>/<bitbucket-repository>/branches/ | jq '.<branch-name>.message') 
    message="${message%\"}" 
    message="${message#\"}" 
    IFS=' ' read -a array <<< $message 
    issue=${array[0]}
    echo $issue > issue.txt
    

    c. Script for JIRA issue transition

    #!/bin/bash
    
    issue=$(<issue.txt)
    curl -D- -u <jira-username>:<jira-password> -X POST --data '{"transition":{"id":"<transition-id>"}}' -H "Content-Type: application/json" https://<jira-base-url>/rest/api/latest/issue/$issue/transitions?expand=transitions.fields
    rm issue.txt
    
  3. Things to keep in mind:

    a. Make sure both scripts are in the same location

    b. Make sure to run 'chmod +X ' on both scripts

    c. Make sure that JIRA issue key is included first in the commit message, e.g. 'JIRA-123 added some stuff'

    d. Make sure to disable concurrent builds in Bamboo in case there's a chance another developer might push a commit to repository when your build is running

P.S. I intentionally included two stages, 'Build' and 'Deployment', in a build plan so that you can build on top of the two scripts and add intermediary scripts (e.g. post a comment to respective JIRA issue when the 'Build' stage passes or fails)

P.P.S I had to strip down my scripts to make this answer shorter, so there might be some mistakes. In case the scripts do not work, please, feel free to tell me about that in comments and I'll see what's broken.

UPDATE: Atlassian did answer my question of why Bamboo won't transition my JIRA ussue statuses in the following way:

I'm afraid the functionality, to autotransition an issue based on the Bamboo build result, is only available if you have Bamboo Cloud + JIRA Cloud. We do have requests open to have this feature with Bamboo server https://jira./browse/BAM-1362 and https://jira./browse/BAM-14044 I encourage you to vote or comment on these requests to increase their visibility.

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多