Fail 1 stage in jenkinsscript

47 views
Skip to first unread message

NickA

unread,
Dec 18, 2017, 5:12:46 AM12/18/17
to Jenkins Users
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
}

NickA

unread,
Jan 22, 2018, 4:56:14 AM1/22/18
to Jenkins Users
Nobody? :-(

I thought this wouldn't be too hard but apparently it is.

That's one of the downsides of Jenkins: support en finding good/detailed information.
I already found answers to other issues on here; but the official help file sucks and isn't always detailed enough or without samples.

Joachim Nilsson

unread,
Jan 22, 2018, 5:18:36 AM1/22/18
to Jenkins Users

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

--
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/c817ba2b-925f-4fdf-9822-e92089637f30%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ST

unread,
Jan 22, 2018, 4:48:09 PM1/22/18
to Jenkins Users
Regarding 1 and 2: I think you should model them based on whether they are dependent on each other:
* Either the two test sets are independently of each other, meaning that even if "Test Set 1" fails then that does not affect in any way the stability/outcome of the "Test Set 2"
  -> If so, run them in parallel, there is no reason to wait with starting "Test Set 2" until "Test Set 1" has completed.
* Or "Test Set 2" builds upon functionality tested by "Test Set 1"
  -> If so, if does not make sense to run "Test Set 2" if "Test Set 1" fails, so dont try-catch any build failure but let Jenkins handle them automatically.

A more general way of looking at this:
* Something that is modeled "serial" means that steps further down the pipe are depending on steps further up the pipe working fine.
* Something that is modeled "in parallel" means that all branches can and should run independently of each other, and the outcome be joined once all branches have completed.

Hope that helps!
 stefan.


To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.

--
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-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/HE1PR07MB0795F65BA415ABAEA28AAA3590EC0%40HE1PR07MB0795.eurprd07.prod.outlook.com.

NickA

unread,
Jan 29, 2018, 8:54:31 AM1/29/18
to Jenkins Users
Thank you for the help; I appreciate it. :-)
Reply all
Reply to author
Forward
0 new messages