Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

How to send SCM changes in build notification email #3438

hkachhia ·
Hello Support,

I would like to send SCM changes in build notification email. Is it possible to send changes/modification list in email ?
  • replies 9
  • views 2628
  • stars 1
jamuirhead ·
Yes. The QB default notification velocity template (I'm assuming your using the default template as you don't say) normally has a section for SCM changesets. Something like this:

#if (!$build.changes.empty)
<h3>Changesets</h3>
<table>
<thead>
<tr>
<td>Repository</td>
<td>User</td>
<td>Date</td>
<td>Change ID</td>
<td>Comment</td>
</tr>
</thead>
#set($row = 0)
#foreach ($change in $build.changes)
#if ($row%2 == 0)
<tr class="even">
#else
<tr class="odd">
#end
#set($row = $row+1)
<td>$change.repositoryName</td>
<td>$util.formatString($change.user)</td>
<td>$util.formatDate($change.date)</td>
<td>$util.formatString($change.id)</td>
<td>$util.formatString($change.comment)</td>
</tr>
#end
</table>
#end

I believe that you will need to enable 'Record SCM Changes' (i.e. set to 'yes') in your Configuration's 'Advanced Settings' for this to work.
robinshen ADMIN ·
If you also want to include the modified files, then nest another loop for each change:
#if (!$build.changes.empty)
<h3>Changesets</h3>
<table>
<thead>
<tr>
<td>Repository</td>
<td>User</td>
<td>Date</td>
<td>Change ID</td>
<td>Comment</td>
<td>Modifications</td>
</tr>
</thead>
#set($row = 0)
#foreach ($change in $build.changes)
#if ($row%2 == 0)
<tr class="even">
#else
<tr class="odd">
#end
#set($row = $row+1)
<td>$change.repositoryName</td>
<td>$util.formatString($change.user)</td>
<td>$util.formatDate($change.date)</td>
<td>$util.formatString($change.id)</td>
<td>$util.formatString($change.comment)</td>
<td>
<ul>
#foreach ($modification in $change.modifications)
<li>path: $util.formatString($modification.path), action: $modification.action</li>
#end
</ul>
</td>
</tr>
#end
</table>
#end
hkachhia ·
Thanks,

Is Quickbuild manage SCM changes/modification in any log file ?

Means if I want to know changes of previous build then is it possible ?
robinshen ADMIN ·
QB writes it into some file co-existing with the build data, and you may access the SCM changes info from build detail page in QB web UI.
Henry ·

Hi Robin,

I'm trying to use the Velocity template that you posted in this thread on QB 8 and it aborts with

10:27:32,211 ERROR - Step 'master>Send_email_to_hek' is failed.
java.lang.RuntimeException: org.apache.commons.mail.EmailException: Invalid message supplied
at com.pmease.quickbuild.bootstrap.BootstrapUtils.wrapAsUnchecked(BootstrapUtils.java:56)
at com.pmease.quickbuild.util.ExceptionUtils.wrapAsUnchecked(ExceptionUtils.java:82)
at com.pmease.quickbuild.util.MiscUtils.sendMail(MiscUtils.java:131)
at com.pmease.quickbuild.util.MiscUtils.sendMail(MiscUtils.java:137)
at com.pmease.quickbuild.plugin.basis.SendMailStep.run(SendMailStep.java:126)
at com.pmease.quickbuild.plugin.basis.SendMailStep$$EnhancerByCGLIB$$e85ebe91.CGLIB$run$10( )
at com.pmease.quickbuild.plugin.basis.SendMailStep$$EnhancerByCGLIB$$e85ebe91$$FastClassByCGLIB$$db526625.invoke( )
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:215)
at com.pmease.quickbuild.DefaultScriptEngine$Interpolator.intercept(DefaultScriptEngine.java:261)
at com.pmease.quickbuild.plugin.basis.SendMailStep$$EnhancerByCGLIB$$e85ebe91.run( )
at com.pmease.quickbuild.stepsupport.Step.doExecute(Step.java:664)
at com.pmease.quickbuild.stepsupport.Step.execute(Step.java:570)
at com.pmease.quickbuild.stepsupport.StepExecutionJob.executeStepAwareJob(StepExecutionJob.java:31)
at com.pmease.quickbuild.stepsupport.StepAwareJob.executeBuildAwareJob(StepAwareJob.java:56)
at com.pmease.quickbuild.BuildAwareJob.execute(BuildAwareJob.java:77)
at com.pmease.quickbuild.grid.GridJob.run(GridJob.java:129)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.commons.mail.EmailException: Invalid message supplied
at org.apache.commons.mail.HtmlEmail.setHtmlMsg(HtmlEmail.java:151)
at com.pmease.quickbuild.util.MiscUtils.sendMail(MiscUtils.java:115)
... 18 more

Can you tell me what's wrong, please?

best regards
Henry

robinshen ADMIN ·

There is a "Evaluate Velocity Template" step, please add this step and feed it with same template and save evaluated result to an external file, then check the file content to see if there is any odd content after the build

Henry ·

Thank you very much. Yer I tried as you requested and executed the velocity-test-step with log-level "TRACE" and got the following step-trace

15:23:37,612 INFO - Checking step execute condition...
15:23:37,613 INFO - Step execute condition satisfied, executing...
15:23:37,730 INFO - Executing pre-execute action...
15:23:37,730 INFO - Running step...
15:23:37,760 DEBUG - Initializing Velocity, Calling init()...
15:23:37,760 TRACE - *******************************************************************
15:23:37,760 DEBUG - Starting Apache Velocity v1.7 (compiled: 2010-11-19 12:14:37)
15:23:37,760 TRACE - RuntimeInstance initializing.
15:23:37,760 DEBUG - Default Properties File: org/apache/velocity/runtime/defaults/velocity.properties
15:23:37,761 TRACE - Default ResourceManager initializing. (class org.apache.velocity.runtime.resource.ResourceManagerImpl)
15:23:37,761 DEBUG - ResourceLoader instantiated: org.apache.velocity.runtime.resource.loader.FileResourceLoader
15:23:37,761 TRACE - FileResourceLoader : initialization starting.
15:23:37,761 DEBUG - Do unicode file recognition: false
15:23:37,761 DEBUG - FileResourceLoader : adding path '/home/master/buildagent/workspace/root/devcomp/maintenance/tooling_admin_only/testVelocity'
15:23:37,761 TRACE - FileResourceLoader : initialization complete.
15:23:37,762 DEBUG - ResourceCache: initialized (class org.apache.velocity.runtime.resource.ResourceCacheImpl) with class java.util.Collections$SynchronizedMap cache map.
15:23:37,762 TRACE - Default ResourceManager initialization complete.
15:23:37,762 DEBUG - Loaded System Directive: org.apache.velocity.runtime.directive.Stop
15:23:37,762 DEBUG - Loaded System Directive: org.apache.velocity.runtime.directive.Define
15:23:37,762 DEBUG - Loaded System Directive: org.apache.velocity.runtime.directive.Break
15:23:37,762 DEBUG - Loaded System Directive: org.apache.velocity.runtime.directive.Evaluate
15:23:37,762 DEBUG - Loaded System Directive: org.apache.velocity.runtime.directive.Literal
15:23:37,762 DEBUG - Loaded System Directive: org.apache.velocity.runtime.directive.Macro
15:23:37,762 DEBUG - Loaded System Directive: org.apache.velocity.runtime.directive.Parse
15:23:37,762 DEBUG - Loaded System Directive: org.apache.velocity.runtime.directive.Include
15:23:37,762 DEBUG - Loaded System Directive: org.apache.velocity.runtime.directive.Foreach
15:23:37,765 DEBUG - Created '20' parsers.
15:23:37,765 TRACE - Velocimacro : initialization starting.
15:23:37,765 DEBUG - Velocimacro : "velocimacro.library" is not set. Trying default library: VM_global_library.vm
15:23:37,765 DEBUG - Velocimacro : Default library not found.
15:23:37,765 DEBUG - Velocimacro : allowInline = true : VMs can be defined inline in templates
15:23:37,765 DEBUG - Velocimacro : allowInlineToOverride = false : VMs defined inline may NOT replace previous VM definitions
15:23:37,765 DEBUG - Velocimacro : allowInlineLocal = false : VMs defined inline will be global in scope if allowed.
15:23:37,765 DEBUG - Velocimacro : autoload off : VM system will not automatically reload global library macros
15:23:37,765 TRACE - Velocimacro : Velocimacro : initialization complete.
15:23:37,765 TRACE - RuntimeInstance successfully initialized.
15:23:37,807 INFO - Executing post-execute action...

... but the "result.txt" file in which I expected velocity-results was empty (0 bytes).

What can be wrong?
Please help me.

Thanx a lot
Henry

robinshen ADMIN ·

It turns out that the template evaluates to an empty string when there are no change sets. I modified the template to print "no changeset" in such case:

#if (!$build.changes.empty)
<h3>Changesets</h3>
<table>
<thead>
<tr>
<td>Repository</td>
<td>User</td>
<td>Date</td>
<td>Change ID</td>
<td>Comment</td>
<td>Modifications</td>
</tr>
</thead>
#set($row = 0)
#foreach ($change in $build.changes)
#if ($row%2 == 0)
<tr class="even">
#else
<tr class="odd">
#end
#set($row = $row+1)
<td>$change.repositoryName</td>
<td>$util.formatString($change.user)</td>
<td>$util.formatDate($change.date)</td>
<td>$util.formatString($change.id)</td>
<td>$util.formatString($change.comment)</td>
<td>
<ul>
#foreach ($modification in $change.modifications)
<li>path: $util.formatString($modification.path), action: $modification.action</li>
#end
</ul>
</td>
</tr>
#end
</table>
#else
No changeset
#end
Henry ·

Hi Robin,

many thanx. It's working now. I did not expect it to fail because of an empty email body in the email-step. But better something like that than a real heavy velocity problem. So everything in QB worked fine from the beginning but I wasn't aware of using it the wrong way. Thanx for your advice.

greetings
Henry