Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×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
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.
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! 😀
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.