How do I debug hooks created with ScriptRunner?

Esther Strom November 30, 2017

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
Daniel Yelamos [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 5, 2017

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
TAGS
AUG Leaders

Atlassian Community Events