Enable a hook for multiple repository using REST-API

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

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 ...

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

 

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
}
]
}

@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

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.

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

 

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 

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 ....

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

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.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

2,011 views 1 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you