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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

0 votes
Answer 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.

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
Community showcase
Published in Bitbucket

Powering DevOps with Bitbucket Server & Data Center

Hi everyone, The Cloud team recently announced 12 new DevOps features that help developers ship better code, faster   ! While we’re all excited about the new improvements to Bitbucket ...

1,826 views 0 7
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you