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

How to add bamboo build log lines into bamboo notification template?

Abhishek S April 20, 2022

I am currently getting bamboo notification emails, but it doesn't have any log lines included in it, I wanted to include last 100 lines of bamboo logs into notification email once bamboo plan is completed.

I was going through this documentation to customize bamboo notification templates but I couldn't find how to fetch log lines into my freemarker template. Please help me with this, I'm new to both freemarker & bamboo.

3 answers

0 votes
Abhishek S February 19, 2023

Hi @Eduardo Alvarenga , can you please help me with this How to put checkout revision number of a build in ... (atlassian.com) ? Was not getting any responses hence reached you.

0 votes
Abhishek S May 9, 2022

Looks like I can't delete answer, so editing it!

0 votes
Eduardo Alvarenga
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 21, 2022

Hello @Abhishek S, Welcome to Atlassian Community!

Depending on the type of notification, some may not include any build logs as they don't have that information. Here's an example showing a logging macro:

[#-- ============================================================================================== @nc.showLogText --]
[#macro showLogs lastLogs baseUrl buildKey ]
[#if lastLogs?has_content]

--------------
Last Logs
--------------

[#list lastLogs as log]
${log.formattedDate} |  ${log.unstyledLog}
[/#list]
[/#if]
[/#macro]

That is included on the common notificationCommonsText.ftl template. You may need to include that file on your custom one like this:

[#include "notificationCommonsText.ftl" ]

Regards,

Eduardo Alvarenga
Atlassian Support APAC 

Abhishek S April 21, 2022

Thank you @Eduardo Alvarenga ! 

In my custom new file, once I include macro as,

<@showLogs lastLogs=? baseUrl=? buildKey=?>

</showLogs>

what will be the values of the above variables (marked as question mark)?

I don't know how to fetch values (what are the keywords for to get logs etc.) for these variables. Can you please help me? 

An example would be highly helpful..

Eduardo Alvarenga
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 21, 2022

Hello @Abhishek S,

If you are including notificationCommonsText.ftl, lastLogs, baseUrl and buildKey will be already declared correctly. So you don't have to assign a value to them.

Check BuildHungHtmlEmail.ftl for good examples of how to print the logs.

You can also find more info here:

 

Kind regards,

 

Eduardo Alvarenga
Atlassian Support APAC 

Abhishek S April 21, 2022

Thank you @Eduardo Alvarenga !

 

I created a custom template called printLogs.ftl, under bamboo-home/templates/notification-templates.

The file has following content:

> cat printLogs.ftl 



[#include "notificationCommonsText.ftl" ]

[@showLogs lastLogs baseUrl buildKey /]

 

But still I'm not getting logs in the notification email. Can you please help me with this?

I've also restarted bamboo using sh start-bamboo.sh

Eduardo Alvarenga
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 22, 2022

Hello @Abhishek S

The lastLogs variable is defined by the com.atlassian.bamboo.notification.buildhung.BuildHungNotification class in the lastLogs object context and will only work in case of hung builds notifications.

If you want to implement such logging on different notifications, you can place a direct http link to the Build logs instead.

Abhishek S April 22, 2022

Hello @Eduardo Alvarenga , Thank you !

Placing http link looks a good idea, but my requirement is to display logs in the notification email, so I tried using iframe in the template as follows,

<iframe src="{bamboo-logs-url}" style= "">

</iframe>

 

But again no logs were displayed, By any chance is there a way to bring logs when build fails? 

Abhishek S April 24, 2022

Hello @Eduardo Alvarenga 

Can you please have a look at my above reply?

Abhishek S April 27, 2022

Hello @Eduardo Alvarenga 

As it seems to have no solution to my problem using existing templates, I'm thinking to create my own notification plugin. Can you please help me how to create a plugin wrt my problem? Maybe some similar plugin as example would help a lot.

 

Hoping for your response, Thank you!

Abhishek S

Eduardo Alvarenga
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 27, 2022

Hi @Abhishek S

You can find more information on plugin development here:

Abhishek S May 9, 2022

Hi @Eduardo Alvarenga 

As soon as build completes it will trigger java files (ex: BuildHungNotification.java etc), which in turn sends notifications. Am I right? If I'm wrong can you please tell me what all happens in background as we get an email notification?

Is it possible to trigger some other java files/bash script as soon as build completes?

 

A reply would be highly helpful.

Eduardo Alvarenga
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 9, 2022

Hello @Abhishek S

Bamboo will call the equivalent notification class depending on the action that has invoked it. For BuildHungNotification, Bamboo will invoke it in case the Hanging build event is triggered.

Currently, the lastLogs object context is only available on the BuildHungNotification class.

There's an existing feature request to enable better log inclusion into notification templates

There are other requests for some extra functionality too:

Make sure to add yourself as a watcher to those tickets so you can get notified once the features are implemented.

Alternatively, you can add a new (final) Stage to your build plan that would contain a script task within a job that would fetch the build logs and build state (success/failure) from the past Jobs in that Plan using the Bamboo REST API and send their logs to your email recipients. Make sure to also exit that final Job within that Stage with the same return code provided by the last Job so it can match success/failure.

 

Regards,

Eduardo Alvarenga
Atlassian Support APAC

Abhishek S May 9, 2022

Hi @Eduardo Alvarenga , thanks for the reply!

Bamboo will call the equivalent notification class depending on action that has invoked it.

Where are these classes located in the installation directory?

 Alternatively, you can add a new (final) Stage to your build plan that would contain a script task within a job that would fetch the build logs.

This is an option to consider, but can you please tell me how to fetch build logs inside task? (if through api please share it..)

Eduardo Alvarenga
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 9, 2022

@Abhishek S

The classes are compiled and cannot be easily read in the Bamboo installation directory. You can explore the Bamboo source code via https://my.atlassian.com/download/source/bamboo (need a proper licence)

For reference, the classes are the ones listed here:

To fetch build logs you can use cURL GET/POST requests, more details here:

 

Regards,

Eduardo Alvarenga
Atlassian Support APAC

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events