Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Bitbucket Scriptrunner Require that a pull request is associated with a valid Jira issue

anovinnikova January 20, 2022

Hello guys,

I'm trying to prevent pr from merging in release branch if Jira issue fix version is not the same as branch name using Require that a pull request is associated with a valid Jira issue built-in script

Screenshot 2022-01-20 133439.png

Screenshot 2022-01-20 133449.png

 

However,

fixVersion = '${mergeRequest.pullRequest.toRef.displayId}'

 

is not working for me, as in Jira issue the names of versions are "2.03", "2.49", and so on and I'm having an error that Edit the PR title (or add commits) to reference an issue from (fixVersion = 'release/5.1'):

Screenshot 2022-01-20 133623.png

 

This error pops out if in Jira issue fixVer we have "5.1" instead of "release/5.1"

However, we can't rename release versions in Jira, so the only way is to write a validator when fixVer in Jira Issue equals target branch name after release prefix and have this merge check only if target branch is a release branch

 

 

So the validation JQL for me should be something like this:

release/JiraIssueFixVer = '${mergeRequest.pullRequest.toRef.displayId}'

(I've tried fixVersion = '${mergeRequest.pullRequest.toRef.displayId}'.split("/")[1]  and that didn't work , and I've also tried substring by index instead of splitting, that didn't work either)

+ condition that target branch is release branch  (run merge check if only merging to release branch, don't run merge check if merging to other branches)

 

Is there any way to get this working? I haven't written any custom merge checks before and can't understand how it can be achieved.

 

 

1 answer

1 accepted

0 votes
Answer accepted

Hi @anovinnikova 

I think your JQL is failing because you need to swap single quotes with double quotes

I believe this script would match a branch named 'release/5.1' with a jira fixVersion = '5.1'

fixVersion in ("${mergeRequest.pullRequest.toRef.displayId.split('/')[1]}")

 

Hope this helps, please let us know if this works for you!

Regards

Yannis

anovinnikova January 27, 2022

Hi!

Thanks for your response and sorry for the late answer.

I've checked the JQL, it works perfect!

Thank you very much for your help.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events