In case anyone has a similar requirement in the future or is interested how I 
solved it, this is what I came up with. I'm sure there's a more graceful 
solution using the build object, but parsing XML in groovy is just so darn 
simple and I was up against a deadline…

import groovy.xml.*
def warnings_text = 
("http://url.com:8080/"+build.getUrl()+"warnings8Result/api/xml?depth=1").toURL().text
def warnings = new XmlParser().parseText(warnings_text)

if (warnings.numberOfNewWarnings.text() == "0") { cancel = true; }


Allen Fisher
Continuous Integration Engineer
MakeMusic, Inc
E: afis...@makemusic.com
P: 952.906.3664
S: allen_fisher
W: www.makemusic.com

On Oct 30, 2012, at 11:58 AM, Ulli Hafner wrote:

> I don't know how to cancel sending an email so my answer is only for the 
> warnings part of your mail. Maybe slide knows how to cancel the sending.
> 
> In your script you basically need a reference to one of the warnings result 
> actions (there is one action per parser). There is no TOKEN yet that exposes 
> all the warnings. If you have this action instance in your script, then you 
> can navigate to the warnings using the available Java methods on that class. 
> E.g. action.result.numberOfAnnotations will give the totals, while 
> action.result.warnings will return the warnings.
> 
> The best way would be if you open the source code of the plug-in to see which 
> methods are available...
> 
> Ulli
> 
> Am 30.10.2012 um 17:47 schrieb Slide <slide.o....@gmail.com>:
> 
>> You basically need to determine how to access the information you want using 
>> Java and then translate that into groovy. You'd want to get at the warnings 
>> publisher for the current build and then look at the API's available for 
>> that to get the information you need. If there is a WARNINGS_NEW token, then 
>> you could look at how the Java creates that token and go from there.
>> 
>> slide
>> 
>> On Tue, Oct 30, 2012 at 8:57 AM, Fisher, Allen <afis...@makemusic.com> wrote:
>> Hi List--
>> 
>> We're on a tear to clean up warnings in our applications. The Warnings 
>> Plugin has been invaluable in that effort (Thanks, Ulli!). It's going to be 
>> a while until we can turn "Warnings as errors" as a global option, so in the 
>> mean time, we want to alert the dev team when the warning count goes up 
>> after a build.
>> 
>> I'm working on using EMAIL-EXT to create the email that goes out for this 
>> issue. I've had some success in listing the counts of new/fixed/total 
>> warnings. It works great except it sends the email for every build, not just 
>> the ones with new errors. According to the documentation for email-ext, I 
>> should be able to put in a pre-send script that sets "cancel" to false. I've 
>> made several stabs at this (I'm not a Groovy guy, so I'm probably missing 
>> something pretty obvious), but no matter what I've done, I can't get it to 
>> cancel the email:
>> 
>> This is one of the attempts, using code I found on stack overflow:
>> 
>> if (${WARNINGS_NEW}==0) { cancel = true; }
>> 
>> Email was triggered for: Success
>> Sending email for trigger: Success
>> Sending email to: afis...@makemusic.com
>> groovy.lang.MissingMethodException: No signature of method: Script1.$() is 
>> applicable for argument types: (Script1$_run_closure1) values: 
>> [Script1$_run_closure1@1fcba664]
>> Possible solutions: is(java.lang.Object), run(), run(), any(), 
>> use([Ljava.lang.Object;), any(groovy.lang.Closure)
>>        at 
>> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)
>>        at 
>> org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:78)
>>        at 
>> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
>>        at 
>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
>>        at 
>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
>>        at Script1.run(Script1.groovy:1)
>>        at groovy.lang.GroovyShell.evaluate(GroovyShell.java:580)
>>        at groovy.lang.GroovyShell.evaluate(GroovyShell.java:618)
>>        at groovy.lang.GroovyShell.evaluate(GroovyShell.java:589)
>>        at 
>> hudson.plugins.emailext.ExtendedEmailPublisher.executePresendScript(ExtendedEmailPublisher.java:322)
>>        at 
>> hudson.plugins.emailext.ExtendedEmailPublisher.sendMail(ExtendedEmailPublisher.java:281)
>>        at 
>> hudson.plugins.emailext.ExtendedEmailPublisher._perform(ExtendedEmailPublisher.java:265)
>>        at 
>> hudson.plugins.emailext.ExtendedEmailPublisher.perform(ExtendedEmailPublisher.java:225)
>>        at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:36)
>>        at 
>> hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:807)
>>        at 
>> hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:782)
>>        at hudson.model.Build$BuildExecution.cleanUp(Build.java:192)
>>        at hudson.model.Run.execute(Run.java:1560)
>>        at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
>>        at hudson.model.ResourceController.execute(ResourceController.java:88)
>>        at hudson.model.Executor.run(Executor.java:236)
>> 
>> 
>> And it still sends the mail.
>> 
>> I also have a question about getting a list of the new warnings in the body 
>> of the email. I'm not sure how to get at them. I've written some python that 
>> pulls out the new warnings using the REST API, but it seems that there 
>> should be a token that I could get at, or is there a groovy call I could 
>> make?
>> 
>> Thanks for all your help!
>> 
>> Allen Fisher
>> Continuous Integration Engineer
>> MakeMusic, Inc
>> E: afis...@makemusic.com
>> P: 952.906.3664
>> S: allen_fisher
>> W: www.makemusic.com
>> 
>> 
>> 
>> 
>> 
>> -- 
>> Website: http://earl-of-code.com
> 
> 


Reply via email to