I'd like to implement logging in a post build action plugin. How would I go about retrieving a BuildLogger object from a BuildContext parameter? is it appropriate to use BuildLogger in a post build step or is it outside of its context?
In a task type plugin I'd use:
final BuildLogger buildLogger = taskContext.getBuildLogger();
I'm looking for something similar, but I only have a BuildContext argument available (in the post build action's init() method).
Cheers,
Gabor
Community moderators have prevented the ability to post new answers.
How about something like:
final BuildLogger logger = buildLoggerManager.getBuildLogger(buildContext.getPlanResultKey());
Would it work? The buildLoggerManager is a dependency injected via setBuildLoggerManager(BuildLoggerManager blm)... I'm not 100% it would work but I'd try this at the beginning.
Thanks Piotr. I've tried it and I do not see anything in the logs. Also tried leveraging the BuildExecutionUpdateManager dependency injection, that did not work either.
My hunch is that writing to the build log is out of scope in a CustomPostBuildCompletedAction, but I've yet to find some documentation which spells this out. I've looked inside Bamboo's source code at BuildLabeller.java, Atlassian's implementation of a CustomPostBuildCompletedAction (svn labeller), which is similar to what I am trying to do (perforce labeller). There's a little bit of logging going on in there, but only to the application log, similar to the commons logging method suggested by Arseny.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
"is that writing to the build log is out of scope in a CustomPostBuildCompletedAction"
Hm... Possible. Could you test what is the value of the buildContext.getPlanResultKey()? Is it full build number (PROJ-PLAN-JOB-N), or only plan (PROJ-PLAN)? Because maybe the logs are going to the Plan log (which is different thing than Plan-Job log) and your messages are visible via viewPlanLog action:
http://your.bamboo:8085/bamboo/chain/viewChainActivityLog.action?planKey=PROJKEY-PLANKEY
if so, you probably need to use PostJobAction (an action run after the Job is finished, not the PostBuildCompletedAction.... Also, it might be worth to check the sources of "PrePostCommand" plugin for Bamboo - for example check this:
I think PrePostCommand plugin outputs something to the Bamboo build logs after Job is/are finished.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
BuildContext.getPlanResultKey() returns 27, which is the current build number. I've also tested buildContext.getPlanKey(), which returns TST-CHK-WOW. I checked http://localhost:6990/bamboo/chain/viewChainActivityLog.action?planKey=TST-CHK Manual build TST-CHK-27 triggered by admin".
I like the idea of using a build processor server module plugin, like the example you linked. That seems to give a perfect type of hook for my plugin. I'd like it to only create the label if the build (up to the labelling itself) has succeeded and also be able to write to the build log. I'll convert my plugin to this type.
Thanks much,
Gabor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am in same boat. From what I read, build processor server module plugin is a version 1 plugin. How can you do a per plan configuration (like enable or disable)?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you just need to simply logging some information to the application log, you could use standard commons logging approach
public class Something { private static final Log logger = LogFactory.getLogger(Something.class); public void myMethod() { logger.info("Something here"); } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the reply. My intent is to write to the build log displayed in Bamboo.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.