Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,295,429
Community Members
 
Community Events
165
Community Groups

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

Edited

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

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

Hi @Robert Giddings _Adaptavist_,

Yes, your post answers my question. 

Thanks,

Niclas Puschmann

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,167 views 2 9
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