Regarding 3: The script language is Groovy so the expansion of ${variablename} 
is only done when using a Groovy-String, which is defined by double quotation 
marks ”, not single ’.
So: change it to
   echo ”Caught-1 : ${exc}”

/Joachim

Från: [email protected] 
[mailto:[email protected]] För NickA
Skickat: den 18 december 2017 11:13
Till: Jenkins Users <[email protected]>
Ämne: Fail 1 stage in jenkinsscript

Hi all,

I have a debug script to experiment with Jenkins Scripting
I have three problems:

1. It's sequential, so first it should configure the machine and install the 
product, then the first test set starts and if that is finished, the second one 
starts.
They all run on 1 machine so I don't think parallel for testset 1 and 2 is 
needed?
But the first issue I had, was that if tests failed in stage 2, then the third 
one didn't start. Tried all kinds of things from the forums but nothing helped.

2. I added try/catch and that works; the status at the end is failed so that's 
good.
But every step shows successful; I don't see Stage 2 and 3 as red.
Is this possible to set separately?

3. And the echo 'Caught : ${exc}' doesn't show any message. Just shows 
expression '${exc}' as text instead of the message itself.

Thank you!

try
{
    node('testmachine')
    {
        stage ('Stage 1 - Setup and install')
        {
            try
            {
                echo 'Starting Stage 1'
                currentBuild.result = 'SUCCESS'
            }
            catch(exc)
            {
                echo 'Caught-1 : ${exc}'
                currentBuild.result = 'FAILED'
            }
        }

        stage ('Stage 2 - Test Set 1')
        {
            try
            {
                echo 'Starting Stage 2'
                int i = 1 / 0;
                currentBuild.result = 'SUCCESS' <- this can't happen in this 
case
            }
            catch(exc)
            {
                echo 'Caught-2 : ${exc}'
                currentBuild.result = 'FAILED'
            }
        }

        stage ('Stage 3 - Test Set 2')
        {
            try
            {
                echo 'Starting Stage 3'
                int i = 1 / 0;
                currentBuild.result = 'SUCCESS' <- this can't happen in this 
case
            }
            catch(exc)
            {
                echo 'Caught-3 : ${exc}'
                currentBuild.result = 'FAILED'
            }
        }
    }
}
catch(exc)
{
    echo 'Caught: ${exc}'
    throw exc
}
--
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 
[email protected]<mailto:[email protected]>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/c817ba2b-925f-4fdf-9822-e92089637f30%40googlegroups.com<https://groups.google.com/d/msgid/jenkinsci-users/c817ba2b-925f-4fdf-9822-e92089637f30%40googlegroups.com?utm_medium=email&utm_source=footer>.
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/HE1PR07MB0795F65BA415ABAEA28AAA3590EC0%40HE1PR07MB0795.eurprd07.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to