Blog #18

How to automation update JIRA tickets status after deploy

# Reason

Imagine your project using Jira to manage tickets. Every sprint, you need to deploy dozens of tickets, and after each deployment, you have to notify the testing team that those tickets have been released to the test or staging environment and need to change their status manually.

It's cumbersome and time-consuming, sometimes leading to unintended issues.

 

# Getting started

Below is my Jira project workflow:

That is my Learn English project :>

 

For my project, after the developer creates a ticket branch and submits a pull request to the develop branch, Jira automation will update the status of that ticket to REVIEW-CODE. Once the code review is approved, and the pull request is merged into the develop branch, Jira automation will again update the status of that ticket to DEVELOPMENT.

Setting as follows:

    1. Auto change to REVIEW-CODE

 

    2 .Auto change to DEVELOPMENT

  or NOT :>

 

The real issue begins at this point. When the develop branch has merged enough ticket branches, corresponding Jira tickets will have the status DEVELOPMENT, right?

After that, I need to deploy them to the staging environment for testing. As before, I had to click on each ticket and manually change the ticket status to QC-TESTING, which took a lot of time.

 

No more long explanations :D. Now, I can update all Jira tickets with the status DEVELOPMENT to QC-TESTING completely automatically as follows:


First, create a Jira webhook with "Issues provided by running the following JQL search":

JQL: status = development

And save the Jira webhook URL

Then, it's time for the dancing with code  hehe:

And make sure your app deploy by Capistrano

 

Create file app/services/jira_service.rb

class JiraService
  def self.update_ticket_status
    staging_url = 'YOUR_JIRA_WEBHOOK_STAGING'
    production_url = 'YOUR_JIRA_WEBHOOK_PRODUCTION'
    url = Rails.env.staging? ? staging_url : production_url
    uri = URI(url)

    header = {
      'Content-Type' => 'application/json'
    }

    # Create the HTTP objects
    http = Net::HTTP.new(uri.host, uri.port)
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    http.use_ssl = true
    request = Net::HTTP::Post.new(uri.request_uri, header)

    # Send the request
    http.request(request)
  end
end

 

Update config/deploy.rb

after 'deploy:finished', 'notification:deploy_success'

namespace :notification do
  desc 'Notification deploy success'
  task :deploy_success do
    on roles fetch(:sitemap_roles, :web) do
      within release_path do
        with rails_env: (fetch(:rails_env) || fetch(:stage)) do
          execute :rake, 'notification:deploy_success', raise_on_non_zero_exit: false
        end
      end
    end
  end
end

 

Create file lib/tasks/notification.rake

namespace :notification do
  desc 'Notification deploy success'
  task deploy_success: :environment do
    JiraService.update_ticket_status
  end
end

 

There you go, now you only need to successfully deploy, and it will automatically update the Jira status for the deployed tickets. You don't have to do it manually anymore :3

Good luck!