Is there an interface (Java) to see if a hook is enabled/disabled? I only need access inside of it's own class.
Is this going to be a Catch-22 scenario, where the class doesn't fire if the hook is disabled?
Hi Justin,
You can use RepositoryHookService.getByKey to retrieve the RepositoryHook for a given repository and hook-key. You can then call RepositoryHook.isEnabled to determine whether it's enabled.
Cheers,
Michael
Hi Micheal,
Using STASH CLI, is it possible to check if a hook is enabled or disabled in STASH ?
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can use the REST api to retrieve the hooks for a repository: https://developer.atlassian.com/static/rest/stash/3.0.4/stash-rest.html#idp2872560
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Micheal. As I am not experienced in REST, it would be great if you can share some sample script if it exist with you. Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Calling the REST endpoint is basically just doing a HTTP request. If you're on linux/mac you can use curl to do that:
curl -X GET -u <repo-admin-user>http://stash.example.com/rest/api/latest/projects/<projectKey>/repos/<repositorySlug>/settings/hooks
And to enable/disable a hook:
curl -X PUT -u <repo-admin-user>http://stash.example.com/rest/api/latest/projects/<projectKey>/repos/<repositorySlug>/settings/hooks/<hookKey>/enabled/true
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am sorry for multiple questions here.
How do I get the hookkey ? Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The first example returns the hooks, which include a key="..." attribute. Use that as the hook-key for the second example.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes. I got the hook key from the first command. However, the following does not seem to work. I am still missing something.
curl -X PUT -u repo-admin-user http://ets-test-cmteam:7990/projects/RNDAP/repos/ap-eclipsetools/settings/hooks/com.atlassian.stash.stash-bundled-hooks:force-push-hook/enabled/true
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You're missing the /rest/api/latest/ part in the URL. Can you try adding that just before the /projects part?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am getting a error code 404.
curl -X PUT -u repo-admin-user "http://ets-test-cmteam:7990/rest/api/latest/projects/RNDAP/repos/ap-eclipsetools/settings/hooks/com.atlassian.stash.stash-bundled-hooks:force-push-hook/enabled/true"
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><status><status-code>404</status-code><message>null for uri: http://ets-test-cmteam:7990/rest/api/latest/projects/RNDAP/repos/ap-eclipsetools/settings/hooks/com.atlassian.stash.stash-bundled-hooks:force-push-hook/enabled/true</message></stat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah apologies, I read our REST documentation wrong. The /true suffix is the problem. The command to enable a hook is
curl -X PUT -u repo-admin-user http://ets-test-cmteam:7990/projects/RNDAP/repos/ap-eclipsetools/settings/hooks/com.atlassian.stash.stash-bundled-hooks:force-push-hook/enabled
To disable the hook, send a DELETE instead:
curl -X DELETE -u repo-admin-user http://ets-test-cmteam:7990/projects/RNDAP/repos/ap-eclipsetools/settings/hooks/com.atlassian.stash.stash-bundled-hooks:force-push-hook/enabled
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You guys are awesome ! Just works fine. Thanks for your patience.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Enable or disable hook works fine with REST API. How about change value?
I'm using an external pre-receive hook with parameters. Can I change a parameter value via rest api?
My response from GET command: {"exe":"/tmp/dev-services/stash/hooks/pre-receive_hook.pl","params":"-M vtester@yahoo.com"}
How I can set new value, for example: params":"-M new-user@gmail.com" ?
Thanks in advance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Valeriy
You need to do a PUT by passing the parameters
1 | curl -X PUT -u repo-admin-user http://ets-test-cmteam:7990/projects/RNDAP/repos/ap-eclipsetools/settings/hooks/com.atlassian.stash.stash-bundled-hooks:force-push-hook/enabled -d '{"parameter_key":"value"}' |
I think this should solve your problem.
Look into this documentation from Atlassian for more info.
https://developer.atlassian.com/static/rest/stash/3.11.3/stash-rest.html
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.