The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Disable and Enable hooks in Bitbucket

Raphael Viana
November 5, 2021

Hi, I'd like to enable and disable hooks, like: 'Reject Force Push', through script.
Is it possible? Exists API to do that action?

 

Thanks!

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
Answer accepted
Ulrich Kuhnhardt _IzymesCo_
Atlassian Partner
November 8, 2021

@Raphael Viana 

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

As a general practice for automating UI tasks, play the scenario in the UI and log the XHR data requests in the browser console. This gives you a good idea what to look for in the REST API spec.

Let me know if that approach works for you.

Best, Ulrich

Izymes - Remove boring from work 

Raphael Viana
November 9, 2021

Hey @Ulrich Kuhnhardt _IzymesCo_ 
thanks so much about your explanation.
I got it and my automation works now.
Thanks!

0 votes
Syahrul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 7, 2021

Hi @Raphael Viana

Welcome to the community!

Currently, Bitbucket doesn't support the Hooks feature. We do have an existing feature request on this, please Vote & Watch the feature request so that you'll receive an update if we have any at:

Meantime, you may want to look into an alternate feature Bitbucket has which is Branch permission where you can enforce specific workflows and prevent errors like a new workspace member deleting the main branch or pushing to branch without creating pull request and approved.

Feel free to let me know if you have any additional questions.

Cheers,
Syahrul

Raphael Viana
November 8, 2021

Hey @Syahrul
I'd like to check that information.

bitbucket_example.png

In BitBuket server we can't enable or disable pre-receive hook with API or
another script access, that action is only possible manually. Correct?

Syahrul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 8, 2021

Hi @Raphael Viana

Apologize for that as I thought you were asking about Bitbucket cloud. If you are looking into Bitbucket server, I believe this documentation could help you:

If you still failing to enable or use your pre-hook I would suggest you raise a support ticket for further assistance.

I hope this helps.

Cheers,
Syahrul

Raphael Viana
November 9, 2021

@Syahrul 
It's possible to enable or disable the hooks using traditional API path as @Ulrich Kuhnhardt _IzymesCo_  said.
It's a great point to put in tutorial or any other content.
As complementing: PUT verb enable hook and Delete disable, so by this way we can control hooks passing his key (obtained through GET to the same endpoint).
Thanks.

Like # people like this
TAGS
AUG Leaders

Atlassian Community Events