Bridging Jira and GitLab: Automating CI/CD Pipelines for Releases

maxim_radugin

Maxim Radugin

Posted on August 25, 2024

Bridging Jira and GitLab: Automating CI/CD Pipelines for Releases

Introduction

Jira Cloud and GitLab are popular productivity and DevOps platforms widely used by many organizations and software development teams. While the integration between these platforms has significantly improved in recent years, there are still areas in common software development tasks that require manual effort or custom integration solutions.

One such area is software releases. In this post, I will demonstrate how to streamline and automate this process, it will be useful for teams who:

  • Plan and manage tasks in Jira;
  • Use Jira versions for planning product milestones and releases;
  • Keep their source code in GitLab;
  • Use GitLab's CI/CD pipelines for deploying and releasing products.

User Story

As a Release Manager, I want GitLab to automatically trigger a release CI/CD pipeline when I change a Jira version's status to 'Released' and its name matches a specific format (e.g., 'v1.2.3'), so that release information is immediately synchronized between Jira and GitLab, reducing manual work and potential errors.

Implementation

To make this happen, we need to:

  • Set up Jira to trigger an action when a version is released.
  • Use the GitLab API to create a matching tag in git repository.
  • Configure GitLab CI/CD to run a release or deploy job when this tag is created.

We'll go through these steps in detail for both Jira and GitLab. This guide uses GitLab's cloud version, but the process is similar for self-hosted GitLab instances.

GitLab Configuration

Create Personal Access Token

You can skip this step if you already have a Personal Access Token (PAT) with the api scope that you can reuse. If not, follow these steps:

  1. In GitLab, navigate to your preferences by clicking on your avatar icon, then Preferences -> Access tokens
  2. Click Add new token, enter a token name (e.g., Jira Release Automation), extend the expiration date, and select the api scope GitLab PAT configuration
  3. Press Create personal access token and note down the token value GitLab PAT created

Modify CI/CD Configuration

In your GitLab project, add the following rule to the release job in your .gitlab-ci.yml file. This ensures the job is triggered only for git tags with a vX.Y.Z format, where X, Y, Z are non-negative integers:

rules:
  - if: '$CI_COMMIT_TAG =~ /^v([0-9]+)\.([0-9]+)\.([0-9]+)$/'
Enter fullscreen mode Exit fullscreen mode

You can find a full example of the .gitlab-ci.yml file here.

Jira Project Configuration

We'll use Jira's built-in Automation to trigger the release pipeline by creating "release" tag in the desired GitLab project:

  1. From the project sidebar, select Automation -> Create rule.
  2. In the rule editor, add a trigger: Version released. Expand More options and set Version name filter to ^v([0-9]+)\.([0-9]+)\.([0-9]+)$. Version released trigger configuration
  3. Press Next, then on the workflow press Add component. Select THEN: Add an action, and add the Send web request component.
  4. Configure the Send web request component:

    • In Web request URL, enter https://gitlab.com/api/v4/projects/<group>%2F<project name>/repository/tags, replacing <group> with your GitLab group and <project name> with your actual project name. If you wonder what %2F is - it is url-encoded value of / character. In my case final URL is https://gitlab.com/api/v4/projects/radugin.com%2Fjira-gitlab-release-automation/repository/tags;
    • Leave HTTP method as POST;
    • Set Web request body to Custom data;
    • Set Custom data to:

      {
          "tag_name": {{version.name.asJsonString}},
          "ref": "main",
          "message": {{version.description.asJsonString}}
      }
      

      This request will create a new tag in specified GitLab repository, Jira version name will be used as a tag name, tag will be created from branch specified in ref (usually main or master), tag message will be populated from Jira version description field.

    • In Headers, add a hidden PRIVATE-TOKEN with your GitLab PAT value.

    Send web request action configuration

  5. Press Next, then Turn on rule. Enter a Rule name (e.g., GitLab Release Automation), and click Turn on rule again.

Verifying Automation

From Jira

  1. Create a version, for example, v1.0.0, add version description.
  2. Perform a version release.
  3. Navigate to Automation -> Audit log and verify that the rule execution was successful. Automation audit log

From GitLab

  1. Navigate to the Tags section and observe the newly created tag. GitLab tags view
  2. Click on the ✅ next to the tag to open the pipeline view, and verify that the release job (in current example - deploy job) was created. GitLab pipelines view

Conclusion

This integration represents a step towards automating and streamlining the release management process for teams using GitLab and Jira, as it bridges an important gap in the DevOps workflow.
The benefits of this automation include:

  • Reduced manual effort in managing releases;
  • Improved synchronization of release information between Jira and GitLab;
  • Decreased likelihood of errors in the release process;
  • Enhanced traceability of releases from project management to code deployment.

While the setup requires some initial configuration, the long-term benefits in efficiency and reliability make it a valuable addition to any team's automation toolset.

Related Materials

💖 💪 🙅 🚩
maxim_radugin
Maxim Radugin

Posted on August 25, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related