To have an issue with a linked deployment, do I need to have a commit with the issue key?
Asked by Nick Daniel:

To get issues to have associated/linked deployments, I am finding success by including the issue key in the commit message. However, the documentation leads me to believe that this should work based on branch name as well (which does appropriately link to the issue, but does not track along with the deployments).

When I use merge commits, and merge in a branch with the issue key, and keep that as the merge comment, then it tracks deployments appropriately (because the issue key from the branch name is now in the commit message history). Is this the only way to do it? The docs are a little unclear on this, and it's slightly unfortunate for the use case I have: PR-linked deployments from branches aren't showing in the Jira issue that they have been deployed to a given environment.

Thank you,  
Nick


Answers:
author: Theodora Boudale
body: Hi Nick,

Are you referring to the Deployments tab, in the Development panel of a Jira Cloud issue?

If so, the deployment is indeed linked only if the commit associated with the deploy contains the issue key in its commit message. See the link below, in the section "Deployments":

* <https://support.atlassian.com/jira-software-cloud/docs/reference-issues-in-your-development-work/>

> **Deployments**
>
> A deployment to an environment, such as production or testing, is linked if a commit associated with the deploy contains the issue key in its commit message. The issue key must be included in the commit to activate this feature.

If the deployments run on a pull-requests definition in your bitbucket-pipelines.yml file, the issue key needs to be present in the last commit of the source branch.

Kind regards,  
Theodora

comments: author: Ivari Horm
body: What happens if the deployment is run from tag instead?

If I currently tag the commit and the deployment pipeline is executed, only that issue is now linked to the new deployment environment.

How can all other issues in the git tree between the current and previous deployment be linked as well?


author: Theodora Boudale
body: Hi Ivari,

A tag is associated with a certain commit, so when you run deployments from a tag, it's again a specific commit that is associated with the deployment.

What I mentioned in the previous post applies in that use case as well. The deployment is linked only if the commit associated with the deploy contains the issue key in its commit message.

Kind regards,  
Theodora


author: Alexander
body: Hi [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086), thanks for your responses, our team is struggling with this issue right now. From what you said, it sounds like it's only possible to link deployments to Jira issues only if you make that deployment from commit associated with certain issue.

In our workflow and in accordance with [Atlassian Deployment Guidelines](https://support.atlassian.com/bitbucket-cloud/docs/bitbucket-deployment-guidelines/), we deploy from \`main\` branch. Once it's ready to be released, we trigger custom pipeline (from the latest state of \`main\`) and deploy to staging environment:

![CGX Git Workflow.drawio.png](https://community.atlassian.com/t5/image/serverpage/image-id/260718i5B7E79769A692111/image-size/large?v=v2&px=999 "CGX Git Workflow.drawio.png")

We noticed that only issues associated with the latest commit in \`main\` (JRA-3) have been linked to the new deployment. But before JRA-3 we have more issues merged (JRA-1, JRA-2). Does it means that these issues will not be linked to the latest deployment and not flagged as "Deployed to Staging"?

If I understand it correctly, it kind of ruins the idea of monitoring deployments from Jira: you will never know where code associated with certain issue was delivered to. Could you please let me know some way to associate previous issues with the latest deployment?

comments: author: Theodora Boudale
body: Hi [@Alexander](/t5/user/viewprofilepage/user-id/5233087),

Thank you for reaching out.

Is your team pushing commits to main branch? If so, what you could do instead is the following:

* Create another branch, e.g. my-feature-a
* Push commits to my-feature-a
* Create a pull request from my-feature-a to main
* When you are ready to merge the pull request, you can use as 'Merge strategy' **Merge commit** or **Squash**, and ensure that the commit message of the merge or squash commit contains all JIRA issue keys that you referenced on my-feature-a.

When you merge a PR from our website and the source branch has more than one commits, then the commit messages of all these commits (including the Jira issue keys) are populated automatically in the message of the merge or squash commit.

The merge or squash commit in main branch will contain all Jira issue keys that were worked on my-feature-a. If you trigger a deployment pipeline for this specific commit, then the deployment will show in all associated Jira issues (in the Development panel).

<br />

If you are already following this strategy, and JRA-1, JRA-2, and JRA-3 are merge commits from other branches, you would need to trigger a deployment for each commit in order for the deployment to show in each Jira issue's Development panel.

One way to work around this would be by creating and pushing to main an empty commit

```
git commit --allow-empty -m "Empty commit for deployment JRA-1 JRA-2 JRA-3"
```

and then trigger a deployment for this empty commit.

Kind regards,  
Theodora


Tags: bitbucket-cloud

cloud