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

Enable a hook for multiple repository using REST-API

Akul Bhatnagar April 14, 2016

Hi team

Is there a way to enable "Simple bitbucket commit checker" configurations for multiple git repos in bitbucket.

I do not want to do that one-by-one. Please suggest a way to perform this in one go.

Please help.

1 answer

1 accepted

0 votes
Answer accepted
Johannes Kilian
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 17, 2016

I wrote a script (perl) to perform this task using Bitbucket-API.

What I basically did within my script

  • Fetched a list of all repositories from Bitbucket
  • Filtered the list for my needs
  • Iterated over the list and enabled/disabled all hooks I wanted to for each repository ..

Just a little basic scripting ...

Akul Bhatnagar April 17, 2016

Hi Kilian, Thanks for writing back.

Even I tried to make things work but rest-api command is not working for me  and I am all stuck.

Can you please share your perl script for me to have a look. I would appreciate.

Akul.Bhatnagar@gmail.com

 

Akul Bhatnagar April 18, 2016

Anyone have any idea, why below rest-api is not working. I am trying to enable a hook called sscc for one the repository using rest-api. It gave me an error.

curl -sS -X PUT -u username:pass http://<hostname>:7990/rest/api/1.0/projects/ABC/repos/sample_repo/settings/hooks/se.bjurr.sscc.sscc/enabled | jq -r

 

OUTPUT:

{
"errors": [
{
"context": null,
"message": "An error occurred while processing the request. Check the server logs for more information.",
"exceptionName": null
}
]
}

Johannes Kilian
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 18, 2016

@Akul Bhatnagar - sorry I'm not allowed to share my code due to our policies ;-/

 

Just an guess, why your curl request might not work: your hook-key "se.bjurr.sscc.sscc" looks strange in comparison to what I use: "com.atlassian.bitbucket.server.bitbucket-bundled-hooks:force-push-hook" (mind the colon)

Try to get the available hooks first (using https://developer.atlassian.com/static/rest/bitbucket-server/4.5.2/bitbucket-rest.html#idp2911664) and check whether the hook key you used is correct

Akul Bhatnagar April 19, 2016

I tried for number of hooks with correct add-on key which their developers have mentioned, but still the same error.

<confused>

Can you share your curl command with me, hope that'll not be considered as a code.

Johannes Kilian
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 19, 2016

I don't use curl very often - for testing I use a REST-client addon for Google Chrome (Postman: https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop).

I just used my standard Bitbucket authorization data and did a simple http GET:

chrome_2016-04-20_08-25-56.png

 

-----

 

Edit: Just tried a simple GET via curl (same REST-call as above):

 

curl -u user:secret http://bitbucket.vitronic.de:7990/rest/api/1.0/projects/ABC/repos/sample_repo/settings/hooks/com.atlassian.bitbucket.server.bitbucket-bundled-hooks:force-push-hook

 

This worked fine and returned the same result as above

 

Akul Bhatnagar April 19, 2016

Hi

I saw your addon key and got a question

com.atlassian.bitbucket.server.bitbucket-bundled-hooks:force-push-hook

:force-push-hook – is this part of key OR you have appended it knowingly 

Johannes Kilian
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 20, 2016

Running a HTTP Get request on http://bitbucket.vitronic.de:7990/rest/api/1.0/projects/ABC/repos/sample_repo/settings/hooks gives a full list of available hooks for the given repository. (Thats what I meant when I wrote above: Try to get the available hooks first (using https://developer.atlassian.com/static/rest/bitbucket-server/4.5.2/bitbucket-rest.html#idp2911664) and check whether the hook key you used is correct)

 

Looking at this list shows that :force-push-hook IS part of the key ....

Johannes Kilian
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 20, 2016

Having a look at my available hooks, I noticed that we've also got your desired SSCC hook available. The correct key seems to be:

se.bjurr.sscc.sscc:pre-receive-repository-hook

Sai N January 31, 2018

Hi,

I wanted to share some additional information on the above, had some trouble initially figuring out how to enable/configure hook settings. In my case we are using 'Yet Another Commit Checker' and our organisation wants to enable enable 'reqireJira Issue' enabled. 

I used the below command to achieve it:

curl -k --user user:secret -X PUT -H "Accept: application/json" -H "Content-Type: application/json" -X PUT https://bitbucket.DOMAIN.com/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks/com.isroot.stash.plugin.yacc:yaccHook/enabled -d '{"requireJiraIssue": true}'

com.isroot.stash.plugin.yacc:yaccHook - is the {hookKey}

 

Thanks.

zhujian July 30, 2020

Hi @Sai N, thanks for the very useful information. I am very curious about whether the 'reqireJira Issue' is defined by the 'com.isroot.stash.plugin.yacc:yaccHook' plugin?

And I want to enable a plugin 'com.ngs.stash.externalhooks.external-hooks:external-merge-check-hook' which needed some params, do you know which **API** I can use to config it(not from the bitbucket UI)?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events