How do I debug hooks created with ScriptRunner? Edited

I added a pre-receive hook using the Protect Git Refs type, following the condition described in the accepted answer here.

Condition:

def commits = refChanges.getCommits(repository)

def regex = "[A-Z]{2,9}-\\d+\\s[A-Za-z]+.*"

commits*.message.any { message ->
   	!(message  ==~ /${regex}/)
}

 

First, the script editor in ScriptRunner gives me an error on the commits.message line, saying "expecting '}', found '-' @ line 5, column 32." I copied and pasted the condition directly from the linked answer, so I'm not sure if it's actually supposed to be a greater-than symbol that got translated or what.  But it did let me save, so I tried to push a commit, and got this message in my git bash window:

"remote: A pre-receive hook failed to execute properly - contact an Administrator"

So my question is, how do I go about debugging issues with hooks created via ScriptRunner? Is there a log somewhere?

 

(EDIT: I changed it to an actual greater-than symbol, and it works now. But I'd still like to know how to debug hooks.)

Also - is there a way to add line breaks to the error message? What I get in git now is this:

remote:
remote: =====================================================
remote: Your commit message must start with a Jira number. Use git commit --amend to update your commit message. (<esc> :wq <enter> to get out of Vim)
remote: =====================================================
remote:

 

I'd like to get something like this:

remote:
remote: =====================================================
remote: Your commit message must start with a Jira number.

Use git commit --amend to update your commit message.

Then type (<esc> :wq <enter> to get out of Vim)
remote: =====================================================
remote:

 

 

1 answer

0 votes

Hi Esther.

What do you mean you want to debug hooks?

Do you debug any other SR feature? If so how?

The word "debug" is quite broadly used, and I want to be 100% sure I know what you mean before I commit to an answer.

Cheers!

Dyelamos

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

349 views 0 1
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you