Marking failure a job finishing SUCCESS

59 views
Skip to first unread message

Antonio Hernandez

unread,
May 19, 2016, 4:19:35 AM5/19/16
to Jenkins Users
Hi everyone,
I'm wondering how to manage the result of a job in other way as jenkins does because i have a job that the only thing it runs is a .jar file that can finsih ok or not but in both cases jenkins marks it as SUCESS, here is an example:



Exception in thread "main" java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"button_1_558"}
Command duration or timeout: 10.10 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'ESMADSRV20', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-86-generic', java.version: '1.7.0_79'
*** Element info: {Using=id, value=button_1_558}
Session ID: 209d81b2-80f5-46a5-b698-c172c66f61fd
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=46.0.1}]
	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.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
	at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
	at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:363)
	at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:413)
	at org.openqa.selenium.By$ById.findElement(By.java:218)
	at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:355)
	at test.firefox.TC05.EditMultipleParameters(TC05.java:1056)
	at test.firefox.TC05.main(TC05.java:118)
	... 5 more
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"button_1_558"}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'ESMADSRV20', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '3.13.0-86-generic', java.version: '1.7.0_79'
Driver info: driver.version: unknown
	at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///tmp/anonymous7442117123704558983webdriver-profile/extensions/fxdr...@googlecode.com/components/driver-component.js:10770)
	at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///tmp/anonymous7442117123704558983webdriver-profile/extensions/fxdr...@googlecode.com/components/driver-component.js:625)
Finished: SUCCESS



¿How to mark a job as failure in this case?


Thanks in advance

zerozer...@gmail.com

unread,
May 19, 2016, 5:12:58 AM5/19/16
to Jenkins Users
Il giorno giovedì 19 maggio 2016 10:19:35 UTC+2, Antonio Hernandez ha scritto:
 
I'm wondering how to manage the result of a job in other way as jenkins does because i have a job that the only thing it runs is a .jar file that can finsih ok or not but in both cases jenkins marks it as SUCESS, here is an example:

Hi,
success or failure of jenkins jobs depends on the return value of scripts/commands you launch from jenkins job configuration, so maybe you just have to check the workflow of your job to be sure you are not ignoring return values.

Anyway, you can also use the Groovy Postbuild plugin to check for lines in console output and change job result accordingly; you can use a groovy script like this:

// Fail for Java exceptions
if(manager.logContains(".*Exception in thread.*")) {
      manager.addErrorBadge("Java exception")
      manager.createSummary("warning.gif").appendText("<h3>Java exception detected.</h3>", false, false, false, "red")
      manager.buildFailure()
}

--
01

Antonio Hernandez

unread,
May 19, 2016, 6:27:06 AM5/19/16
to Jenkins Users
Thanks a lot zerozerounouno!!!!!!!!

I introduced the groovy script as you written and it's working fine!!!!!!!! 
Thanks again!
Reply all
Reply to author
Forward
0 new messages