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:
- In GitLab, navigate to your preferences by clicking on your avatar icon, then
Preferences
->Access tokens
- Click
Add new token
, enter a token name (e.g.,Jira Release Automation
), extend the expiration date, and select theapi
scope - Press
Create personal access token
and note down the token value
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]+)$/'
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:
-
From the project sidebar, select
Automation
->Create rule
. -
In the rule editor, add a trigger:
Version released
. ExpandMore options
and setVersion name filter
to^v([0-9]+)\.([0-9]+)\.([0-9]+)$
. -
Press
Next
, then on the workflow pressAdd component
. SelectTHEN: Add an action
, and add theSend web request
component. -
Configure the
Send web request
component:- In
Web request URL
, enterhttps://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 ishttps://gitlab.com/api/v4/projects/radugin.com%2Fjira-gitlab-release-automation/repository/tags
; - Leave
HTTP method
asPOST
; - Set
Web request body
toCustom data
; - Set
Custom data
to: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{ "tag_name": {{version.name.asJsonString}}, "ref": "main", "message": {{version.description.asJsonString}} }
ref
(usuallymain
ormaster
), tag message will be populated from Jira version description field. - In
Headers
, add a hiddenPRIVATE-TOKEN
with your GitLab PAT value.
- In
-
Press
Next
, thenTurn on rule
. Enter aRule name
(e.g.,GitLab Release Automation
), and clickTurn on rule
again.
Verifying Automation
From Jira
- Create a version, for example,
v1.0.0
, add version description. - Perform a version release.
- Navigate to
Automation
->Audit log
and verify that the rule execution was successful.
From GitLab
- Navigate to the
Tags
section and observe the newly created tag. - 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.
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.