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
4,295,838
Community Members
 
Community Events
165
Community Groups

Pre receive hooks to reject push on file that has blacklisted keywords

Hi,

We are trying to implement a pre receive hook at repository level. We want to reject push that contains sql files having blacklisted keywords. Currently don't see an option to enable/add custom pre-receive hook via Bitbucket UI.

Following the shell script we used as pre-commit hook in local repo.

########################

#!/bin/bash

LIST="DROP|COMMIT|TRUNCATE|ROLLBACK"

if git rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
else
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi

for FILE in `git diff-index -name-status --cached $against – | cut -c3 | grep -E 'dbsql'` ; do

#Check if the file contains one of the words in LIST
if grep -iwE $LIST $FILE; then
echo $FILE." has one of the following blacklisted keywords you don't want to commit. Please remove it"
echo "Blacklisted keywords : DROP|COMMIT|TRUNCATE|ROLLBACK"
exit 1
fi
done
exit

##########################################

We have few questions:

a) Is it possible to add custom pre-receive hooks via bitbucket UI and provide the content as shell script?

b) Is it mandatory that content of pre-receive hook should be written in groovy scripting language?

Current setup:

Current pre hook settings in UI are below

image.png

When we click add hook, it is re-directing to market place.

 

Our use case : We want developers to block pushing the sql files having blacklisted keywords like DROP,COMMIT etc at bitbucket server side.

 

1 answer

0 votes

Hi Linson,

There are a few different ways of going about creating your own custom logic for use with pre-receive hooks within Bitbucket - and ultimately all of our recommended options for doing so are going to be found in the following document:

I'd recommend going through the various solutions outlined in that article, and seeing which of the options there would likely work best for your team. And although we can't help with creating the hook itself, if you have any questions regarding this document as a whole you're always welcome to shoot us a ticket over at Atlassian Support!

Thanks again, and I hope you and your team have a great weekend! 😀

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,170 views 2 9
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