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

How to Dynamically Retrieve and Delete GitHub Branches Using Jira Automation?

zhakyp zhoomart uulu
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 20, 2024

 

Hi everyone, I’m trying to set up a Jira automation rule that automatically deletes a GitHub branch when an issue is transitioned to "Done". The challenge I'm facing is that our branch names vary, but they always include the Jira issue key. I’ve managed to delete branches by hardcoding the branch name in the web request, but I want to make this dynamic. How can I retrieve the exact branch name linked to the issue from GitHub?

1 answer

1 accepted

1 vote
Answer accepted
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 20, 2024

Hi @zhakyp zhoomart uulu -- Welcome to the Atlassian Community!

You could try calling the endpoint to list the branches, filter within the rule using the issue key, and then use the result for your deletion.

Kind regards,
Bill

zhakyp zhoomart uulu
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 21, 2024

Hi , @Bill Sheboy 

Thanks for your suggestion! I was able to retrieve the branch names using a GET web request, and it returned the following:

LUN-12-jira-org, LUN-13-test, main

I used the smart value {{webResponse.body.name}} to extract the branch names, but now I'm struggling with filtering to get only the branch name that contains the issue key. Do you have any advice on how I can achieve this within the Jira automation rule?

Kind regards,
Zhakyp

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 21, 2024

You may use the match() function with a regular expression to extract the one needed: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/#match--

As the regular expression will need to be dynamic, to contain the key, there is an extra step using a created variable.  Let's assume there is an {{issue.key}} for use.

  • action: create variable
    • name: varRegEx
    • value: ({{issue.key}}.++)
  • action: to search for the value
    • {{webResponse.body.name.match(varRegEx)}}

That will produce a list of matches (zero to many) so consider what to do when there are more than one matches.

Lunara Inashova August 21, 2024

Hi @Bill Sheboy ,

I am also facing the same issue as @zhakyp zhoomart uulu .Thank you for the detailed explanation and the solution using the match() function with a regular expression. I tried it, and it worked perfectly in the scenario where the branch name follows the pattern {{issue.key}}.++

In my case, we don't have a strict branching strategy, so the branch names can vary significantly. Sometimes, the branch name might just be the issue key (e.g., ABC-123), and other times it might have additional text attached to the issue key (e.g., ABC-123-feature).

Given this variability, is there a way to make the regex more dynamic? I want to ensure that the automation works regardless of whether the branch name is just the issue key or has additional characters appended. Any suggestions on how to adjust the approach for this more flexible matching?

Thanks again for your help!

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 21, 2024 edited

Hi @Lunara Inashova -- Welcome to the Atlassian Community!

The regular expression I provided assumed at least one character after the issue key, and may be modified to meet your needs.  Please review the match() documentation as it includes a link to the Java pattern expressions rules are based upon to see other patterns.

For the cases you note, a simple expression could be this instead:

{{issue.key}}.*

Kind regards,
Bill

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
atlassian, team '25, conference, certifications, bootcamps, training experience, anaheim ca,

Want to make the most of Team ‘25?

Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.

Learn more
AUG Leaders

Upcoming Jira Events