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

MergeChecks script error

Kha Hoang May 17, 2023

We have the MergeChecks script in BitBucket and it has been working; however, after upgraded ScriptRunner to version 8.1.0, the script is broken and gave error:

# Script: get the merge from branch value and to branch value, split it by / and get the second value after splitted.  compare them and if the values are the same, allow the merge.

# e.g. toBranch = develop/asc  and fromBranch = feature/asc/<Jira-issue>

def toBranch = mergeRequest.pullRequest.toRef.displayId
def fromBranch = mergeRequest.pullRequest.fromRef.displayId

def str1;
def str2;

str1 = toBranch.split('/')[1];
str2 = fromBranch.split('/')[1];

if (str1 == str2) {
    return false;
} else {
    return true;
}
After upgraded ScriptRunner, It gave the following error.  How do we fix it?
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during semantic analysis: Expression [BinaryExpression] is not allowed: toBranch.split(/)[1]

java.lang.SecurityException: Expression [BinaryExpression] is not allowed: toBranch.split(/)[1]
	at org.codehaus.groovy.control.customizers.SecureASTCustomizer$SecuringCodeVisitor.assertExpressionAuthorized(SecureASTCustomizer.java:1084)
	at org.codehaus.groovy.control.customizers.SecureASTCustomizer$SecuringCodeVisitor.visitBinaryExpression(SecureASTCustomizer.java:1300)
	at org.codehaus.groovy.ast.expr.BinaryExpression.visit(BinaryExpression.java:60)
	at org.codehaus.groovy.control.customizers.SecureASTCustomizer$SecuringCodeVisitor.visitBinaryExpression(SecureASTCustomizer.java:1303)
	at org.codehaus.groovy.ast.expr.BinaryExpression.visit(BinaryExpression.java:60)
	at org.codehaus.groovy.control.customizers.SecureASTCustomizer$SecuringCodeVisitor.visitExpressionStatement(SecureASTCustomizer.java:1173)
	at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:41)
	at org.codehaus.groovy.control.customizers.SecureASTCustomizer$SecuringCodeVisitor.visitBlockStatement(SecureASTCustomizer.java:1137)
	at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:70)

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events