I am using Scriptrunner to create a custom event handler for a repository.
Currently the event handler gets triggered every time a new branch is created in any repository or project. I want to be able to restrict the custom event handler only to a specific repository.
The BranchCreatedEvent class enables me to apply my program logic to a specific repository but as of right now I haven't found a solution to prevent the event handler to be triggered by a different repository.
I have successfully tried to restrict a different kind of event handler to a specific repository using the Bitbucket web UI. Unfortunately there isn't this kind of configuration option available for creating custom event handlers. Is it even possible to change the setting from
'Repositories/ Projects: All' to 'Repositories/ Projects: specificRepository' for custom event handler?
I have also checked the documentation at: https://scriptrunner.adaptavist.com/6.5.0-p5/bitbucket/StashEventHandlers.html?utm_source=product-help#_applying_event_handlers_to_specific_projects_repositories
I'm not sure if I understand the sample code correctly and I haven't successfully tried it that way. I assume that the code restricts only the if block and does not change the display of the BitBucket web UI.
My code:
import com.atlassian.bitbucket.event.branch.BranchCreatedEvent
Thank you for your question.
You are correct. Currently in order to restrict Custom Listeners, you need to do so programmatically.
And yes, you are correct. In order code example, doSomething() will only happen when the repository was "foo".
However you should use the code
event.repository.slug == "foo"
Here is a link to the latest edition of the relevant docs:
https://docs.adaptavist.com/sr4bib/latest/features/listeners/custom-listeners
However, I will also look at making Custom Listeners in future like all the other listeners, with a selectable project/repo tree.
Please let me know if that helps answer your question?
Kind regards,
Robert Giddings
Hi @Robert Giddings _Adaptavist_,
Yes, your post answers my question.
Thanks,
Niclas Puschmann
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.