Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Delete branch after JIRA status changes

Vikas kumar July 25, 2023

Hi Team,

 

I have requirement as below, could you help me in providing the necessary links or inputs to achieve this.

Currently, after merging our feature branch to release(PROD), will delete the feature manually after PROD signoff received.

Now I need to handle it using JIRA. Like as below.

1. Track feature branch name in JIRA. can we do this using https://support.atlassian.com/jira-software-cloud/docs/process-issues-with-smart-commits/  ???

2. Once we move the JIRA status to Done, it should create pull request for the feature branch to release , how to automate this?

3.  Once approver approved.

4. Merge the pull requested and delete feature.  how to automate this?

 

Thanks,

Vikas

 

1 answer

1 accepted

0 votes
Answer accepted
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 26, 2023

Hi Vikas and welcome to the community!

Since you created the question in the Bitbucket forum with the tag 'bitbucket-cloud', I assume that your repositories are hosted in Bitbucket Cloud?

 

1. Track feature branch name in JIRA. can we do this using https://support.atlassian.com/jira-software-cloud/docs/process-issues-with-smart-commits/ ???

 

Smart commits are useful if you want to transition an issue, comment on an issue, or track time for an issue when you make a commit.

If you want to track a feature branch in Jira, you can create a branch in your repo that includes the Jira issue key name in its name. E.g. for the issue TEST-10, you can create a Bitbucket branch named feature-TEST-10. This way the branch will show up in the Jira issue in the Development panel.

You can also use the Jira issue key in the commits you make to this branch, if you want these commits to show in the Development panel.

 

2. Once we move the JIRA status to Done, it should create pull request for the feature branch to release , how to automate this?

 

It is possible to create Automation rules in Jira:

You could create an Automation rule with the trigger Issue transitioned and then add as an action Send web request. The web request can use our API to create a PR in Bitbucket Cloud:


The tricky thing here is that when the trigger is Issue transitioned, the values of any associated branches and repos are not available. In theory, a single Jira issue could be referenced by multiple different branches in multiple different repositories and Jira wouldn't know which one you want to create a pull request for.

You could solve this by creating custom fields in Jira that will hold the values of the source branch name, the destination branch name, the workspace id, and the repo slug. These fields would need to be filled in with the correct values by the user before transitioning the issue, and you could then use their values in the automation rule.

Additionally, when you configure the web request, it is important to include the data

"close_source_branch": true

so that the source branch gets deleted once you merge the PR.

 

3. Once approver approved, merge the pull requested and delete feature. how to automate this?

What action are you referring to by approval?

Do you mean a PR reviewer selecting the Approve button in the Pull Request, on Bitbucket Cloud website? Or something different?

Kind regards,
Theodora

Vikas kumar July 27, 2023

Thanks Theodora, I will try the first two points.

 

For the 3rd one, yes you are right it's PR reviewer. It basically links to my 2nd question. 

Once JIRA is implemented and moved to PROD, after changing JIRA status to Done. It should create PR request in all the associated repository. Then, my 3rd question comes "Once PR reviewer approved those PR's, merge the pull request and delete feature. how to automate this?

In a high-level when JIRA moved to Done and create PR request, it should send mail to PR reviewer. Once reviewer approved this, it should merge and delete feature branches automatically.

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 28, 2023

Hi Vikas,

When a user gets added as a PR reviewer, they will get an email from Bitbucket informing them that they have been added as a reviewer in a PR. This happens anyway, so you don't need to configure something extra.

We don't have any automation that automatically merges a PR once it is approved. However, the Merge button of the PR is on the same page as the Approve button. If you only have one reviewer and if that reviewer has enough permissions to merge the PR, they can merge the PR right after they approve it.

It is possible to configure in a repository a webhook that gets triggered when a PR gets approved. This webhook could then send a request to a server of yours and then your server could use our API to merge the PR. I'm not sure if this is worth the trouble though. It might be easier to have the PR reviewer merge the PR as soon as they approve it, but that's up to you to decide.

If the PR was created with the option "close_source_branch": true, then the source branch will get deleted after the PR is merged.

Kind regards,
Theodora

Vikas kumar July 28, 2023

Thanks Theodora, that makes sense. Sure I will try on the webhook part.

Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 31, 2023

You are very welcome Vikas.

One more thing I forgot to mention earlier regarding the email to the PR reviewer: a user will automatically receive an email when they are added as a PR reviewer unless they have disabled notifications on https://bitbucket.org/account/settings/notifications/. Notifications are enabled by default, but it would be good to ask the users who are usually PR reviewers to make sure they have not disabled this setting.

Please feel free to reach out if you have any questions.

Kind regards,
Theodora

Vikas kumar July 31, 2023

Thanks Theodora, I checked and it's enabled and have not changed anything in the settings .

 

Thanks,

Vikas

Like Theodora Boudale likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events