Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Logging from a post build action plugin

Gabor Maghera December 27, 2011

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

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
PiotrA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 28, 2011

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.

Gabor Maghera December 28, 2011

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.

PiotrA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 28, 2011

"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:

https://bitbucket.org/atlassian/bamboo-prepostcommand-plugin/src/a0d1a3369010/src/main/java/com/sysbliss/bamboo/plugins/prepostcmd/action/PostBuildCommandServerAction.java#cl-47

I think PrePostCommand plugin outputs something to the Bamboo build logs after Job is/are finished.

Gabor Maghera December 28, 2011

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

robin wang July 8, 2014

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)?

1 vote
Arseny Kovalchuk December 27, 2011

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");
   }
}

Gabor Maghera December 28, 2011

Thanks for the reply. My intent is to write to the build log displayed in Bamboo.

TAGS
AUG Leaders

Atlassian Community Events