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

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

Avatar

1 badge earned

Collect

Participate in fun challenges

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

Challenges
Coins

Gift kudos to your peers

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

Recognition
Ribbon

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!

Leaderboard

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,464,249
Community Members
 
Community Events
176
Community Groups

Create Git Commit Hook

Hi Community,

We are using BitBucket cloud service to host all our Git repositories.

I would like to enforce some rule on each commit for some repositories. Technically I want to apply a Git commit hook on server side to valid any incoming push and allow/reject it by a bunch of checks.

On BitBucket cloud I can only find the configuration of Webhooks. From the documentation I was not able to clarify my following questions:

  • The Webhook sends an HTTP POST request to remote server, is the response evaluated and has it impact on the incoming Git push? Or is it fire and forget?
  • Is it possible to achive commit hooks by using the Webhook functionality?

 

Thanks a lot, Roman

 

2 answers

1 accepted

1 vote
Answer accepted

I think I found the answer (https://community.atlassian.com/t5/Bitbucket-questions/Does-Bitbucket-Cloud-support-git-pre-receive-hooks/qaq-p/950235):

Git pre-commit hook is currently support in BitBucket DataCenter, but NOT in BitBucket Cloud.

BitBucket WebHooks are NOT an equivalent to that.

There is a ticket pending (might need more votes): https://jira.atlassian.com/browse/BCLOUD-10471

 

Regards, Roman

Everyone reading `this` please vote on https://jira.atlassian.com/browse/BCLOUD-10471

Hi Roman,

You can enable a webhook so every time you commit you can create a pull request, and manage a review of the code with that.

 You can make a Bitbucket REST API call (via curl or postman) to enable/disable specific hooks programmatically.

1. GET your repo hook keys via /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks

2. PUT request for hook to be enabled  (DELETE disables the hook) via /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks/{hookKey}/enabled

Best Regards

Laura

Hi @laura.devita

thanks for you quick reply. Creating a PR on each commit is not exactly what I am looking for.

Actually I try to find a way on server side (BitBucket) to prevent a commit being  stored in BitBucket Git repository.

This can be useful for a couple reason. Mainly when you want to apply a quality gate that needs to be passed before a commit is accepted. E.g. developer should follow a certain code format rule or the commit message must contain some required information.

Apply this on all developer systems is a high effort and can of course be bypassed by the developers easily.

So it is a better approach to ensure those things on Git server side by what is called a commit hook.

It is also possible to apply these quality gates later on (thru a central CI instance) but it is much more charme to apply some check already when the commit is send and reject it if checks are failing.

Regards, Roman

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events