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?
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
That will produce a list of matches (zero to many) so consider what to do when there are more than one matches.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.