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

Is it possible to restrict the execution of a custom event handler to a specific repository?

Niclas Puschmann October 13, 2021

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?

img.PNG

 

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

BranchCreatedEvent event = event
def repo = event.repository
def branch = event.branch
def branchName = event.branch.displayId
if(repo.name == "foo") {
      doSomething()
    }

1 answer

0 votes
Robert Giddings [Adaptavist]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 26, 2021

Hi  @Niclas Puschmann,

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

Niclas Puschmann November 26, 2021

Hi @Robert Giddings [Adaptavist],

Yes, your post answers my question. 

Thanks,

Niclas Puschmann

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events