Published on: April 12, 2021
12 min read
Check out how to integrate GitLab self-managed with Atlassian Jira to connect your merge requests, branches, and commits to a Jira issue.

This is the second in a series of posts on GitLab Jira integration strategies. The first post explains how to integrate GitLab.com with Jira Cloud.
The advantages of a GitLab Jira integration are clear:
Here's a step-by-step guide of everything you need to know to achieve a GitLab Jira integration.
As you approach configuring your GitLab project to Jira, you can choose from two options that best fit your company or organization's needs. You can either:
It should be noted that each GitLab project can be configured to connect to an entire Jira instance. That means one GitLab project can interact with all Jira projects in that instance, once configured. Therefore, you will not have to explicitly associate a GitLab project with any single Jira project.
GitLab offers several different options that allow you to integrate Jira in a way that best fits you and your team's needs based on how you’ve set up your Jira software. Let’s take a deeper look into how to set-up each of these available options.
The first step in setting up your Gitlab Jira integration is having your Jira configuration in order.
Jira Server supports basic authentication. When connecting, a username and password are required. Note that connecting to Jira Server via CAS is not possible. Set up a user in Jira Server first and then proceed to Configuring GitLab.
Jira Cloud supports authentication through an API token, and in order to begin the process you need to start by creating one within Jira. When connecting to Jira Cloud, an email and API token are required. Set up a user in Jira Cloud first and then proceed to Configuring GitLab.
Create an API token here: https://id.atlassian.com/manage-profile/security/api-tokens

Jira API token creation

Jira API token copy to clipboard
As mentioned above, you can begin setting up the Jira integration either by using a service template that defaults all GitLab projects to pre-fill Jira values or you can set up at an individual project level.
To set up a service template:

GitLab Service Templates
2a. For each project, you will still need to configure the issue tracking
URLs by replacing
![]()
Issue Tracker ID
To set up a individual project template:

Enable Jira Integration

Select Trigger Action
In order to obtain a transition ID, do the following:
Note: The transition ID may vary between workflows (e.g., bug vs. story), even if the status you are changing to is the same.

Transition ID
Your GitLab project can now interact with all Jira projects in your instance and the project now displays a Jira link that opens the Jira project.
When you have configured all settings, click Test settings and save changes.

Test settings and save changes
It should be noted that you can only display issues from a single Jira project within a given GitLab project.
The integration is now activated:

Active Jira Integration
By now you should have configured Jira and enabled the Jira service in GitLab. If everything is set up correctly you should be able to reference and close Jira issues by just mentioning their ID in GitLab commits and merge requests.
Jira issue IDs must be formatted in uppercase for the integration to work.
When GitLab project has Jira issue tracker configured and enabled, mentioning Jira issue in GitLab will automatically add a comment in Jira issue with the link back to GitLab. This means that in comments in merge requests and commits referencing an issue, e.g., PROJECT-7, will add a comment in Jira issue in the format:
USER mentioned this issue in RESOURCE_NAME of PROJECT_NAME|LINK_TO_COMMENT:
ENTITY_TITLE

Reference Jira issues
For example, the following commit will reference the Jira issue with PROJECT-1 as its ID:
git commit -m "PROJECT-1 Fix spelling and grammar"
Closing Jira Issues
Jira issues can be closed directly from GitLab when you push code by using trigger words in commits and merge requests. When a commit which contains the trigger word followed by the Jira issue ID in the commit message is pushed, GitLab will add a comment in the mentioned Jira issue and immediately close it (provided the transition ID was set up correctly).
There are currently three trigger words, and you can use either one to achieve the same goal:
where PROJECT-1 is the ID of the Jira issue.
Notes:
Let’s consider the following example:
In the following screenshot you can see what the link references to the Jira issue look like.

GitLab link references
Once this merge request is merged, the Jira issue will be automatically closed with a link to the commit that resolved the issue.

Jira Issue auto closes when GitLab MR merges
When using the Jira DVCS configuration, there are several different configurations you can make that are dependent on how your Jira/GitLab instances are managed.
While signed in to the GitLab account that you want Jira to use to connect to GitLab, click your profile avatar at the top right, and then click Settings > Applications. Use the form to create a new application.
For the Redirect URI field, enter https://<gitlab.example.com>/login/oauth/callback, replacing <gitlab.example.com> with your GitLab instance domain. For example, if you are using GitLab.com, this would be https://gitlab.com/login/oauth/callback.
Note: If using a GitLab version earlier than 11.3, the Redirect URI must be https://<gitlab.example.com>/-/jira/login/oauth/callback. If you want Jira to have access to all projects, GitLab recommends that an administrator create the application.

Admin Creates Integration
Tip: To ensure that regular user account maintenance doesn’t impact your integration, create and use a single-purpose jira user in GitLab.
Note: If you’re using GitLab.com and Jira Cloud, we recommend you use the GitLab for Jira app, unless you have a specific need for the DVCS Connector.

Check api in Applications

Application was created successfully

Go to DVCS in Settings

Click Link to start new integration
Select GitHub Enterprise for the Host field.
In the Team or User Account field, enter the relative path of a top-level GitLab group that you have access to, or the relative path of your personal namespace.

Add new account
In the Host URL field, enter https://<gitlab.example.com>/, replacing <gitlab.example.com> with your GitLab instance domain. For example, if you are using GitLab.com, this would be https://gitlab.com/.
Note: If using a GitLab version earlier than 11.3 the Host URL value should be https://<gitlab.example.com>/-/jira
For the Client ID field, use the Application ID value from the previous section.
For the Client Secret field, use the Secret value from the previous section.
Ensure that the rest of the checkboxes are checked.
Jira takes up to a few minutes to know about (import behind the scenes) all the commits and branches for all the projects in the GitLab group you specified in the previous step. These are refreshed every 60 minutes.
In the future, we plan on implementing real-time integration. If you need to refresh the data manually, you can do this from the Applications -> DVCS accounts screen where you initially set up the integration:

Refresh data manually
To connect additional GitLab projects from other GitLab top-level groups (or personal namespaces), repeat the previous steps with additional Jira DVCS accounts.
For troubleshooting your DVCS connection, go to GitLab Docs for more information.
In our next blog post we'll look at Usage.
Cover image by Mikołaj Idziak on Unsplash.
Enjoyed reading this blog post or have questions or feedback? Share your thoughts by creating a new topic in the GitLab community forum.
Share your feedback