How do I inject managers into my plugin

How do I inject managers into my plugin? Specifically an event listener.

I found this documentation but it seems to be outdated. BuildResultsSummaryManager is out dated…
https://developer.atlassian.com/server/bamboo/how-do-i-inject-managers-into-my-plugin/

Hi @schow,

There are different ways of doing so. The following works for me:

  1. Annotate your class with Scanned (Component if it is a component).
  2. Annotate the field you want to import with ComponentImport. In the link you provided it can be like
@ComponentImport
private BuildResultsSummaryManager buildResultsSummaryManager;
  1. Annotate your constructor that accepts the same type of the object you want to inject as a parameter with Inject like
@Inject
public MyClass(final BuildResultsSummaryManager buildResultsSummaryManager) {
   this.buildResultsSummaryManager = buildResultsSummaryManager;
}

Hope this helps.
Ian

Keep in mind that this example uses Spring Scanner, which has some host product compatibility constraints. Spring scanner 2 is only compatible with Bamboo 5.14+. For older versions, use Spring Scanner 1. See also https://bitbucket.org/atlassian/atlassian-spring-scanner/src/master/ and https://bitbucket.org/atlassian/atlassian-spring-scanner/src/1.2.x/README.md?at=1.2.x&fileviewer=file-view-default

1 Like

Thanks, I used the annotates and got something working. I found that calling certain methods I would get a weird error like:
[INFO] [talledLocalContainer] 2018-09-19 14:46:14,561 INFO [17-BAM::Default Agent::Agent:pool-32-thread-1] [DefaultErrorHandler] Recording an error: Fail Handling Plugin custom build post complete action failed to run : TEST-GM-JOB1 : failed to lazily initialize a collection of role: com.atlassian.bamboo.resultsummary.AbstractResultsSummary.labellings, could not initialize proxy - no Session

Am I missing something additional?

For Bamboo there are essentially 2 modes of operations - on the agent or on the server. (Local agents are technically on the server but I would highly recommend ignoring that since if you introduce remote agents into the mix - your code will break).

The reason I bring this up is that the server code can inject pretty much anything it wants. Things running on the agents - don’t have access to the database, user authentication etc. They get the build info and the directory. They can generate data and send it back to the server to be processed. In your case BuildResultsSummaryManager is dependent on the database thus not available on the agent.

That said - you can break your code up and do things before the build gets sent to the remote agent (take a look at https://developer.atlassian.com/server/bamboo/custom-build-definition-transformer-module ). You can then use the postBuildProcesserServer to interpret on the server.

There used to be a pretty graph on developer.atlassian.com that explained the build cycle for Bamboo, but it seems to have been removed (there doesn’t seem to be much of documentation for Bamboo nowadays). I swear there was a more straight forward module to handle intra-agent-server communications as well.

I think you are looking for this one @danielwester https://developer.atlassian.com/server/bamboo/bamboos-build-process/

@schow what are you trying to achieve?

Yep. That’s the one. @schow if you take a look at that one you’ll quickly see which plugin points are on the agent versus server.