How to exit a Groovy postbuild script gracefully?

817 views
Skip to first unread message

MCSF

unread,
Jan 28, 2015, 7:04:52 PM1/28/15
to jenkins...@googlegroups.com
Hello,
I want to be able to exit the Groovy postbuild step gracefully if the build status was ABORTED.
Here is what I have now:

   def buildstatus = manager.build.getResult() 
   if ("$buildstatus".equalsIgnoreCase( "ABORTED" ) ) 
   {
     manager.addShortText("Build $buildstatus; exiting Groovy", "red", "white", "0px", "white")
     throw new RuntimeException("buildstatus is $buildstatus ") 
   }
   // do normal stuff if build was not aborted


The above code works, but it spews a bunch of Groovy errors onto the build page:

Groovy script failed:
java.lang.RuntimeException: buildstatus is ABORTED 
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
	at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
	at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:71)
	at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:81)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:54)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:190)
	at Script1.run(Script1.groovy:5)
	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 org.jvnet.hudson.plugins.groovypostbuild.GroovyPostbuildRecorder.perform(GroovyPostbuildRecorder.java:312)
	at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:804)
	at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:776)
	at hudson.model.Build$BuildExecution.post2(Build.java:183)
	at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:725)
	at hudson.model.Run.execute(Run.java:1709)
	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
	at hudson.model.ResourceController.execute(ResourceController.java:88)
	at hudson.model.Executor.run(Executor.java:231)

Kanstantsin Shautsou

unread,
Feb 3, 2015, 2:26:01 PM2/3/15
to jenkins...@googlegroups.com
Just don't throw error, especially RuntimeException.
Reply all
Reply to author
Forward
0 new messages