Fail 1 stage in jenkinsscript

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Fail 1 stage in jenkinsscript

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

Re: Fail 1 stage in jenkinsscript

NickA
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.

--
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/c2ea8567-ff34-40af-b6b8-4a0703b002fa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

SV: Fail 1 stage in jenkinsscript

Joachim Nilsson-3
In reply to this post by NickA

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: [hidden email] [mailto:[hidden email]] För NickA
Skickat: den 18 december 2017 11:13
Till: Jenkins Users <[hidden email]>
Ä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 [hidden email].
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.

--
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/HE1PR07MB0795F65BA415ABAEA28AAA3590EC0%40HE1PR07MB0795.eurprd07.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Fail 1 stage in jenkinsscript

Stefan Thurnherr
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.


On Mon, Jan 22, 2018 at 11:18 AM, Joachim Nilsson <[hidden email]> wrote:

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: [hidden email] [mailto:[hidden email]] För NickA
Skickat: den 18 december 2017 11:13
Till: Jenkins Users <[hidden email]>
Ä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 [hidden email].
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.

--
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/HE1PR07MB0795F65BA415ABAEA28AAA3590EC0%40HE1PR07MB0795.eurprd07.prod.outlook.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/CABwQARtVxiXjybWOE-x2Rk3MZQOtJb_DzkWvTMgcSdv%3DLWiXqA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Fail 1 stage in jenkinsscript

NickA
In reply to this post by NickA
Thank you for the help; I appreciate it. :-)

On Monday, December 18, 2017 at 11:12:46 AM UTC+1, NickA wrote:
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/8a980762-1b96-4882-b137-e625dcac05ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.