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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 30, 2018 in Marketplace Apps

Three tips for boosting your board's efficiency with Story Maps

Trello is one of the most effective tools for driving your sprints. It's customizable for every Agile team and product owners and Scrum masters (SM) love it. However, Agile teams often struggle with:...

863 views 2 9
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