Jenkins, pipeline multibranch and exception

瀏覽次數:131 次
跳到第一則未讀訊息

sbru...@gmail.com

未讀,
2018年7月11日 凌晨4:49:522018/7/11
收件者:Jenkins Users
Hello everybody,

I'm new to the mailing list and new pipeline-multibranch user in Jenkins, I didn't know Groovy at the beginning of the week.

I'm trying to throw an exception in a 'Jenkinsfile' file after calling the 'sh' command.
Example:

if (! sh (script: filename, returnStatus: true)) {
     throw new RuntimeException ("Errrrooooorrrrrrrrrrr!")
}

I still get the following message:
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Java.Lang.String

Is it possible to throw an exception in a Jenkinsfile? What's the problem ?


Regards,
Samuel

Victor Martinez

未讀,
2018年7月11日 中午12:03:132018/7/11
收件者:Jenkins Users
does it work the below snippet?

retCode = sh script: filename, returnStatus: true
if (retCode != 0) {
    error "Errrrooooorrrrrrrrrrr!"
}

Cheers

Samuel Brunel

未讀,
2018年7月11日 下午2:49:052018/7/11
收件者:jenkins...@googlegroups.com
Victor,

It’s ok to throw exception but I need to add 
currentBuild.result = 'FAILURE
to exit with failure from Jenkinsfile.

the documentation is not easy to navigate, impossible to find 'error' for example.


Thanks,

Samuel

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/cf58c5c7-a5dd-45d1-b493-8b3e693abbdb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reinhold Füreder

未讀,
2018年7月12日 凌晨2:59:302018/7/12
收件者:jenkins...@googlegroups.com

Hi Victor,

 

In case you don’t have to do any special/custom/proprietary additional action/handling, then just

sh script: filename

… should do the trick as well: because by default a non-0 exit code of sh step will exit the pipeline with an error/failure IIRC.

 

HTH Reinhold

回覆所有人
回覆作者
轉寄
0 則新訊息