Jenkins, pipeline multibranch and exception

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Jenkins, pipeline multibranch and exception

sbrunel62
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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/3ffec259-9f55-4e5b-af19-0de52157e3b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Jenkins, pipeline multibranch and exception

Victor Martinez
does it work the below snippet?

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

Cheers

--
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 [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

Re: Jenkins, pipeline multibranch and exception

sbrunel62
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

On 11 Jul 2018, at 18:03, Victor Martinez <[hidden email]> wrote:

does it work the below snippet?

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

Cheers

--
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 [hidden email].
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.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/05927977-4852-4FA1-BDCA-6127C8A5D72D%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

RE: Jenkins, pipeline multibranch and exception

Reinhold Füreder

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

 

 

From: [hidden email] <[hidden email]> On Behalf Of Samuel Brunel
Sent: Mittwoch, 11. Juli 2018 20:49
To: [hidden email]
Subject: Re: Jenkins, pipeline multibranch and exception

 

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



On 11 Jul 2018, at 18:03, Victor Martinez <[hidden email]> wrote:

 

does it work the below snippet?

 

retCode = sh script: filename, returnStatus: true

if (retCode != 0) {

    error "Errrrooooorrrrrrrrrrr!"

}

 

Cheers

 

--
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 [hidden email].
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.

 

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/05927977-4852-4FA1-BDCA-6127C8A5D72D%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/VI1P190MB00474DA7B595E3B2A4666CC1F7590%40VI1P190MB0047.EURP190.PROD.OUTLOOK.COM.
For more options, visit https://groups.google.com/d/optout.