How to limit a Git branch name to 50 characters

412 Views Asked by At

I am currently trying to make a script using groovy to implement as a Pre-Hook for Jira using ScriptRunner. The script is supposed to block branch if they are more than 50 characteres long. I am new to Grrovy and stack overflow and i am quite lost.

def branchName = currentBuild.rawBuild.getEnvironment(listener).get('GIT_BRANCH')
def branchNameLength = branchName.length()
def branchNameLimit = 50

if (branchNameLength > branchNameLimit) {
error("branch name too long; limited at: ${branchNameLimit} characteres. Actual name lenght: ${branchNameLength} caracteres.")
}

This is the code I did but it doesn't seems to work, do you have any tips or solution to help resolve this problem?

I tried doing it using a RegEx but I failed too. What I want is to limit the number of characteres whenever you try to create a branch.

0

There are 0 best solutions below