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

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

365 views 0 6
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