DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Automating PMO Meetings With n8n Automation
  • Navigating Software Development With Kanban
  • Streamlining Development Workflows With Internal Platforms
  • Automation and Integration: Curing Your Context Switching Headache

Trending

  • The Human Side of Logs: What Unstructured Data Is Trying to Tell You
  • Unlocking the Potential of Apache Iceberg: A Comprehensive Analysis
  • Cookies Revisited: A Networking Solution for Third-Party Cookies
  • Start Coding With Google Cloud Workstations
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Auto-Transition of JIRA Issues With Bamboo Build Results

Auto-Transition of JIRA Issues With Bamboo Build Results

You can use Bamboo and Bitbucket integrated with JIRA to automate the status changes of your tickets. This tutorial shows you how.

By 
Amit Anand user avatar
Amit Anand
·
Jun. 22, 17 · Tutorial
Likes (13)
Comment
Save
Tweet
Share
9.2K Views

Join the DZone community and get the full member experience.

Join For Free

If you are working on a JIRA issue, you need to change the status of the issue every time you perform any activity on your code, like changing or modifying the code or deploying the code for testing. You change the status with a single click, but nowadays, everyone likes automation and for things to be done within a fraction of a second. Also, due to a heavy code base, some builds take a longer time to process, and until then, the developer or manager has to wait to change the status of the JIRA ticket.

Atlassian, the enterprise company providing many useful software development and collaboration tools, has provided the integration of Bamboo builds with JIRA workflows. This helps you to configure a workflow in a JIRA application. Therefore, a JIRA issue can be transitioned to another state in your workflow according to the result of the build process (successful or failed).

The “transition id” of the issue plays a key role in changing the status of the JIRA issue automatically. Every customized workflow has its own unique transition id. Apart from the transition id, which is relevant to the transition of the issue state in JIRA, there is a unique step id for each step name in JIRA.

We can define different JIRA workflows according to organizational need. A JIRA workflow is a set of transitions and statuses which help an issue to move from one state to other. There are some default workflows that cannot be edited, but you can copy and use these workflows to create your own.

You can create your own workflows or import other workflows from Atlassian Marketplace.

Solution to This Problem

Pre-requisites to implement this use case are:

  • JIRA, Bamboo, and Bitbucket should be tightly integrated with a single sign-on.Image title
  • The Bamboo Fail Build Trigger plugin must be installed from this link.
    • Task type as Script is required in a Bamboo server.
    • Knowledge of how to use or choose the correctRest API for Bamboo and JIRA.

    Image titleImage title

    First, you need to get the transition ID of an issue from a workflow. Suppose we have a predefined workflow named “Software Simplified Workflow for Project DEV” applied to any project. This workflow has the below steps:

    Step Name (id)

    Linked Status

    Transitions (id)

    To Do (1)

    TO DO

    To Do (11)
    >> To Do
    In Progress (21)
    >> In Progress
    Done (31)
    >> Done

    In Progress (6)

    IN PROGRESS

    To Do (11)
    >> To Do
    In Progress (21)
    >> In Progress
    Done (31)
    >> Done

    Done (11)

    DONE

    To Do (11)
    >> To Do
    In Progress (21)
    >> In Progress
    Done (31)
    >> Done

    In the above workflow, we have Transitions(id), which is unique for all transitions. For the current workflow, it's11 for "TO DO," 21 for "In progress," and 31 for "Done." Another workflow may have other numbers as ids.

    We can utilize this transition id for changing the transition of any particular issue.

    Solution: Let’s Implement This

    Step 1

    Create a project in Bamboo and, inside this project, create a couple of plans. Plan 1, with the name “IT,” will have multiple jobs inside it, and inside the default job, we can create multiple tasks.

    The screenshot below has a plan with the name “IT.” In this plan, dependencies are added to trigger child plans so that after the completion of this task, the child plan may get a trigger. We can have multiple child plans and, as of now, we have single child plan with the name “Issue_Transition.”

    Step 2

    Now we need to add the script in Tasks of bamboo plan 2 with the name as “Issue_Transition” and also we need to add trigger as “After plan fail” to execute if Plan key is failing.

    This script is responsible for fetching all JIRA issue with status as “In Progress” and transition the issue on the basis of Bamboo build result, either Successful or Failed

    If build Result is Successful, all issue from “In Progress” will be transitioned to “Done” state

    And if build result is Failed, all issue from “In Progress” will be transitioned to “To Do” State

    In order to achieve this one should have knowledge on JSON Rest API and JQ to parse JSON files.

    Below script is responsible for the conditional transition of the issue.You need to add this script in bamboo Task type as Script section

    You can track all history of transitioning an issue from History tab in JIRA.

    #!/bin/bash
    
    #Below mention script is responsible for fetching the issue with "In Progress" status from running JIRA instance with project name as DEV
    #message=$(curl -u username: password -X GET -H "Content-Type: application/json" http://<hostname>:8080/rest/api/2/search?%3DDEV%20%20AND%20STATUS%3D%20%22TO%20DO%22 | jq-linux32 ".issues|.[]|.key")
    
    message_issue=$(curl -u username: password -X GET -H "Content-Type: application/json" http://<hostname>:8080/rest/api/2/search?%3DDEV%20%20AND%20STATUS%3D%20%22In%20Progress%22 | jq-linux32 ".issues|.[]|.key")
    
    read -a array <<< $message_issue
    issue=${array[0]}
    echo $message_issue > get_jira_issue.json
    
    #Below mention script is responsible for checking latest build state in BAMBOO with project name as <bamboo_project_name>-IT and perform transition of issues
    #For Software Simplified Workflow for Project DEV transition ids are To Do (11) In Progress (21) Done (31)
    
    message_build_state=$(curl -u username:password -X GET -H "Content-Type: application/json" http://<hostname>:8085/rest/api/latest/result/<bamboo_project_name>-IT?expand&buildstate&)
    value=`echo $message_build_state > buildStatus`
    ResultbuildState=`cat buildStatus | grep -oP '(?<>)[^<]+' buildStatus | head -n 1`
    echo "Result status of latest build is  $ResultbuildState"
    echo $ResultbuildState> build_result.json
    #Now Transition will be done on the basis of build result above
    #TRANSITION OF ISSUE FROM “In Progress" or Current state to " To Do"  DURING BUILD EXECUTION
    if [ "$ResultbuildState" == "Failed”]
    then
    cat get_jira_issue.json
    for i in `cat get_jira_issue.json`
    do
    issue=`echo $i | tr -d '"'`
    echo $issue
    message=`curl -u username:password -X POST --data '{"transition":{"id":"11"}}' -H "Content-Type: application/json" http://<hostname>:8080/rest/api/latest/issue/$issue/transitions?.fields
    done
    fi
    if [ "$ResultbuildState" == "Successful" ]
    then
    #TRANSITION OF ISSUE FROM  "In Progress" or Current state to " Done"  DURING BUILD EXECUTION
    for i in `cat get_jira_issue.json`
    do
    echo "$i"
    issue=`echo $i | tr -d '"'`
    message=$(curl -u username:password -X POST --data '{"transition":{"id":"31"}}' -H "Content-Type: application/json" http://<hostname>:8080/rest/api/latest/issue/$issue/transitions?.fields)
    done
    fi

    Benefits:

    • Improved working proficiency.
    • Reduced the human intervention and for transitioning of the issue.
    • No license add-on required.
    Jira (software) Bamboo (software) Build (game engine) workflow Software development

    Opinions expressed by DZone contributors are their own.

    Related

    • Automating PMO Meetings With n8n Automation
    • Navigating Software Development With Kanban
    • Streamlining Development Workflows With Internal Platforms
    • Automation and Integration: Curing Your Context Switching Headache

    Partner Resources

    ×

    Comments
    Oops! Something Went Wrong

    The likes didn't load as expected. Please refresh the page and try again.

    ABOUT US

    • About DZone
    • Support and feedback
    • Community research
    • Sitemap

    ADVERTISE

    • Advertise with DZone

    CONTRIBUTE ON DZONE

    • Article Submission Guidelines
    • Become a Contributor
    • Core Program
    • Visit the Writers' Zone

    LEGAL

    • Terms of Service
    • Privacy Policy

    CONTACT US

    • 3343 Perimeter Hill Drive
    • Suite 100
    • Nashville, TN 37211
    • support@dzone.com

    Let's be friends:

    Likes
    There are no likes...yet! 👀
    Be the first to like this post!
    It looks like you're not logged in.
    Sign in to see who liked this post!