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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Can you concatenate strings in scriptrunner JQL query?

I have a merge check I am trying to setup that prevents a merge from happening if the target branch does not match a field found in an associated JIRA Issue.

I am using the "Require that a pull request is associated with a valid JIRA issue" merge check that comes with scriptrunner and am also using the following JQL which almost gives me what I want.

Target_Baseline ~ '${mergeRequest.pullRequest.toRef.displayId}

Target_Baseline is a free text custom field in JIRA. The problem is that the right side of the equation evaluates to something slightly different than the left (shown below) and it fails the check and does not allow the merge

v1.0.0 ~ 'v1.0.0T'

that extra T at the end of the target branch is throwing a wrench in things. Is there any way to manually concatenate a string to the end of the Target_Baseline or perhaps even remove that character from the target branch?

Any and all help is appreciated!

1 answer

Hi @Omar Morales 

The JQL expression is an GString and it has two phases of execution:

1. In the first one, all Groovy expression are interpolated into String

2. In the second, interpolated string is passed to JIRA for execution

In the first phase in all expression which are in "${}" you have full power of Groovy language to do anything You would like to do, for example:

${mergeRequest.pullRequest.toRef.displayId.substring('T', '')}

more about GString interpolation You can read here: https://groovy-lang.org/syntax.html#_string_interpolation

 

I think also that You are missing closing ' char or the first one is redundant, it could be just

Target_Baseline ~ ${mergeRequest.pullRequest.toRef.displayId.substring('T', '')}

 

Kind Regards,

Tomasz Wozniak

Software Engineer - ScriptRunner for Bitbucket

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,741 views 10 16
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you