Can a Bamboo plugin be notified when a plan is deleted? Edited

I'm developing a plugin that stores settings per plan in PluginSettings. I'm wondering if there's some sort of callback mechanism whereby my plugin can be notified when a plan is deleted so it can remove its corresponding settings.

I'm fairly new to Bamboo development, so apologies if this obvious. :)

EDIT:

In case another n00b runs across this, here's my working example. Just need to add the appropriate bambooEventListener block in your atlassian-plugin.xml.

 

package com.example.bamboo.testPlugin

import com.atlassian.bamboo.event.ChainDeletedEvent;
import com.atlassian.bamboo.plan.PlanKey;
import com.atlassian.event.api.EventListener;
import com.atlassian.event.api.EventPublisher;
import com.atlassian.plugin.spring.scanner.annotation.component.Scanned;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;

import javax.inject.Inject;


@Scanned
public class PlanDeletionListener implements DisposableBean {
    private static final Logger log = LoggerFactory.getLogger(PlanDeletionListener.class);
    @ComponentImport private final EventPublisher eventPublisher;

    @Inject
    public PlanDeletionListener(EventPublisher eventPublisher) {
        log.info("PlanDeletionListener instantiated.");
        this.eventPublisher = eventPublisher;
        eventPublisher.register(this);
    }

    @EventListener
    public void onChainRemoved(@NotNull ChainDeletedEvent chainDeletedEvent) {
        PlanKey key = chainDeletedEvent.getPlanKey();
        String message = ("Plugin received deletion event for plan with key "+key.getKey());
        log.info(message);
    }

    public void destroy() throws Exception {
        eventPublisher.unregister(this);
        log.info("PlanDeletionListener destroyed.");
    }
}

 

1 answer

1 accepted

Yes, there's com.atlassian.bamboo.event.ChainDeletedEvent

You can create listener

@EventListener
public void onChainRemoved(@NotNull ChainDeletedEvent chainDeletedEvent)
{
     ....do what you need
}

 

Thanks, that sent me down the right path.

Suggest an answer

Log in or Join to answer
Community showcase
Renan Battaglin
Published May 18, 2017 in Bamboo

FAQ: How to Upgrade Bamboo Server

Bamboo 5.9 will no longer be supported after June 12, 2017. What does this mean? As part of our End of Life policy, Atlassian supports major versions for two years after the first major iteratio...

1,074 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot