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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

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

Atlassian Community Events