Goal
When committing to git, we mention in the comment some task from Jira by name, after which two things happen:
- in GitLab, the name of the issue turns into an active link to it in Jira
- in Jira, a comment is added to the task with links to the commit and the user who made it, and the mention text itself is also added
Setting
- We need a Jira user with write permissions. You can use an existing one, it is important to remember that all comments in Jira when mentioning tasks from the git will fall on behalf of this user, so it's better to create a new one, name it, say, GitLab, and add it to Jira with write rights to all your projects.
- We need a GitLab user with administrator rights in each of the projects that we will connect. For each project, integration is configured separately.
- In GitLab, open the project, go to Settings -> Integrations. Scroll down and see project services with a long list of services that can be connected.
- We find Jira in this list, a form appears

- Put a tick Activeto activate the link.
- As you can see from the form, you can separately configure the desired behavior for commits and merge requests.
- We introduce Web URL your company in Jira, for example 'https://companyname.atlassian.net'
- Jira API URL - filled in if you have another Jira instance, the default value will be Web URL.
- fields Username / Email и Password/Token are filled in according to whether you are using Jira Server or Jira Cloud. In the case of Jira Server, you enter the Username and password of the user under whose name the comments will be added. In the case of Jira Cloud, you put down an email and a token that you can get .
- Field Transition ID(s). If you want, say, that when a task is mentioned, it is automatically closed, then in this field you need to enter the ID of the transition to the closed state. This ID can be obtained via the API:
https://companyname.atlassian.net/rest/api/2/issue/ISSUENAME-123/transitionswhere ISSUENAME-123 is the name of some task in the desired state. You will receive JSON with the transitions array, from which you can take the desired id.
As a result, GitLab's Settings -> Integrations Jira now has a green indicator:

and the item will appear in the project menu Jira, which leads to the corresponding project in Jira:
Usage:
When we write a comment to a commit (no matter what tool we use to work with git), we can add the name of the tasks in text form (without quotes or any special characters like @)
bugfix XPROJECT-123, XPROJECT-124as a result, a comment will fall on the corresponding task:

and an active link will appear in the gitlab:

Source: habr.com



