I want to enable a hook via REST api for a repository in the inherited-from-project state.
How can I do this via REST api?
When I call
/rest/api/1.0/projects/some/repos/another/settings/hooks/com.nerdwin15.stash-stash-webhook-jenkins:jenkinsPostReceiveHook/enabled
I get
{
"details": {
"key": "com.nerdwin15.stash-stash-webhook-jenkins:jenkinsPostReceiveHook",
"name": "Webhook to Jenkins for Bitbucket Server",
"type": "POST_RECEIVE",
"description": "Webhook for notifying a configured endpoint of changes to this repository.",
"version": "4.4.2",
"configFormKey": "com.nerdwin15.stash-stash-webhook-jenkins:jenkinsPostReceiveHook-config-form",
"scopeTypes": [
"REPOSITORY",
"PROJECT"
]
},
"enabled": true,
"configured": true,
"scope": {
"type": "PROJECT",
"resourceId": 534
}
}
I want to set now that scope=type:PROJECT via REST api if its in any other state.
I could not find the needed http call to do so.
Please help.
Thanks in advance,
Maik
Hi Maik!
Thanks for reaching out. Can you please help me understand a bit better what you're trying to achieve?
You are trying a PUT request on:
/rest/api/1.0/projects/some/repos/another/settings/hooks/com.nerdwin15.stash-stash-webhook-jenkins:jenkinsPostReceiveHook/enabled
Correct?
That endpoint is specifically for enabling a hook at the repository level. Therefore, I expect the result to have scope=type:REPOSITORY, not scope=type:PROJECT as your JSON indicates. Can you verify this?
To have the hook inherit the project scope, you need to remove the setting at the repository level (if it exists), by calling
DELETE /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks/{hookKey}
Validate the settings are inherited properly by calling
GET /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks/{hookKey}
You should then see scope=type:PROJECT for that hook.
See the documentation on these endpoints here.
Edit: To enable a hook at the project level (scope=type:PROJECT), use the following endpoint:
PUT /rest/api/1.0/projects/{projectKey}/settings/hooks/{hookKey}/enabled
Note: if a hook has settings at the repository level, that will have priority.
See documentation here
Hi Dick,
perfect, thank you!
That was the missing piece of information.
Maik
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.