[SOLVED] Do Bamboo remote agents have access to PluginLicenseManager?

I think its safe to say at this point, the answer is: no, the class is not available.

Daniel, thanks heaps for your suggestion about using a Pre-Build Queued Action and using the build context to pass data. This is totally the way to go for this kind of thing - I have it working!

The CheckLicense class I linked to earlier is so old it doesn’t even compile any more. I hacked around with it and long story short most of the events that I’d be interested in catching like PluginLicenseExpiredEvent are never thrown in the first place. It seems like functionality has been reduced to just the bare miniumum so that plugin upgrades etc can be handled nicely.

Just incase anyone else needs to pass data like this in the future, here’s how you do it:

  1. Create a class implementing CustomPreBuildQueuedAction and inject PluginLicenceManager
  2. Add a preBuildQueuedAction stanza to atlassian-plugin.xml (see example above)
  3. In the public BuildContext call() method of your new class, add the license lookup and save the result as custom build data:
    public BuildContext call() throws InterruptedException, Exception {
        String license;
        if (!pluginLicenseManager.getLicense().isDefined() ||
                pluginLicenseManager.getLicense().get().getError().isDefined()) {
            license = "ERROR";
        } else {
            license = "OK ... you rock!";
        }

        // from https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-share-data-between-Bamboo-and-Bamboo-remote-agent-from-a/qaq-p/564124
        buildContext.getBuildResult().getCustomBuildData().put("server", "test3");
        buildContext.getBuildResult().getCustomBuildData().put("license", license);
        return buildContext;
    }
  1. In your Task, you can look the data up:
        // licence check
        buildLogger.addErrorLogEntry("GOT THIS " + taskContext.getBuildContext().getBuildResult().getCustomBuildData().get("server"));
        buildLogger.addErrorLogEntry("GOT THIS " + taskContext.getBuildContext().getBuildResult().getCustomBuildData().get("license"));
  1. Final things to do to stop plugin failing to load on remote agents:

    • Beans that should only be on the server (like this one) get annotated @BambooComponent and @BambooImport for injected beans.
    • Make sure you optional the UPM dependencies!
    <Import-Package>
        com.atlassian.upm.*;resolution:="optional",
        *
    </Import-Package>

:beers:

1 Like