Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

trying to write a bitbucket pre-receive hook in groovy to run pylint or other test



I'm creating a groovy script which I've set as a pre-receive hook so as to run pylint on any .pp files and fail when the score is too low.


I set the hook at a URL like this one:


I've found lots of snippets of groovy code but I can't find a way to get a list of the actual files being committed...

I've run out of ideas trying random things, and am hoping someone can help. Any help at all would be gratefully received.



output when you do a git push

remote: =====================================================================
remote: pmansfield testing pre-commit hook
remote: repository name: paulm
remote: refChange type: refs/heads/master
remote: commit message: DEVOPS-2744 testing 25
remote: hello pmansfield
remote: =====================================================================


===groovy script===

import com.atlassian.bitbucket.content.Change
import com.atlassian.bitbucket.content.ChangeSummary
import com.atlassian.bitbucket.hook.HookResponse
import com.atlassian.bitbucket.repository.RefChange
import com.atlassian.bitbucket.repository.Repository
import com.atlassian.bitbucket.user.ApplicationUser
import com.atlassian.bitbucket.user.Person

import com.onresolve.scriptrunner.canned.bitbucket.util.BitbucketCannedScriptUtils

def msg = new StringBuilder()
msg << "pmansfield testing pre-commit hook\n".toString()

def repository = repository as Repository
msg << "repository name: $ \n".toString()

// DOESNT WORK stuff from ChangeSummary
//def changeSummary = changeSummary as Collection<ChangeSummary>

// DOESNT WORK stuff from Changes
//def changes = changes as Collection<Changes>
//for (change in changes) {
// msg << "change path: ${change.getPath()}\n".toString()

// stuff from RefChange
def refChanges = refChanges as Collection<RefChange>
for (refChange in refChanges) {
msg << "refChange type: ${refChange.refId}\n".toString()

def commits = refChanges.getCommits(repository)
for (commit in commits) {
msg << "commit message: ${commit.getMessage()}\n".toString()

def authors = refChanges.getCommitAuthors(repository)
for (author in authors) {
msg << "hello $ \n".toString()

def hookResponse = hookResponse as HookResponse
hookResponse.out().write BitbucketCannedScriptUtils.wrapHookResponse(msg)

return true

0 answers

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across Jira Cloud instance.   📢 Get y...

161 views 7 8
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you