Get stage name in pipeline

1,011 views
Skip to first unread message

Sureshkumar Ramar

unread,
Aug 23, 2019, 6:42:52 AM8/23/19
to jenkins...@googlegroups.com
Hi,
i am using jenkins pipeline. i want to send the failed stage name to the developer. is there a way to capture the failure stage in jenkins. it should work in parallel stages also. 

--
Thanks & Regards,
Suresh Kumar R

Faad Sayaou

unread,
Aug 23, 2019, 7:37:04 AM8/23/19
to jenkins...@googlegroups.com

  you can include this in every stage
  FAILED_STAGE=env.STAGE_NAME

and in your email you can call the property $FAILED_STAGE.
hope it helps


--
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/CAM6nqfeQ9sPjgT-nPf%2BhWDY-nuE30%3D3O6No-10WLT3G%2B-jiPvg%40mail.gmail.com.


--

Best Regards / Mit freundlichen Grüßen,

Faad Sayaou,

Embedded Systems for Mechatronics Masters student | FH Dortmund | Germany

Fachhochschule Dortmund

University of Applied Sciences and Arts

Emailfaad...@gmail.com


Sureshkumar Ramar

unread,
Aug 24, 2019, 9:12:54 AM8/24/19
to jenkins...@googlegroups.com
Hi,
Thanks for your answer and this should work when your pipeline only has sequence stages. In parallel stages two or more stage got failed then one stage name will replaced by another stage name . So, i can't get all the failed stage. Is there any other way?


amit r

unread,
Aug 24, 2019, 2:41:59 PM8/24/19
to Jenkins Users
Hi,
Even if you have parallel stages, you still can have different stages printed with any info that u wish.
Lets assume that you call each stage with different name.
You can define for your stage withEnv function what will print also your stage name or just like the msg above mentioned.

Did you try it and didnt work?
Share your pipeline if have more issue..

Amit Rintzler

בתאריך יום שבת, 24 באוגוסט 2019 בשעה 16:12:54 UTC+3, מאת Sureshkumar Ramar:
> Hi,
> Thanks for your answer and this should work when your pipeline only has sequence stages. In parallel stages two or more stage got failed then one stage name will replaced by another stage name . So, i can't get all the failed stage. Is there any other way?
>
>
>
>
> On Fri, 23 Aug, 2019, 5:06 PM Faad Sayaou, <faa...@gmail.com> wrote:
>
>
>
>
>   you can include this in every stage
>   FAILED_STAGE=env.STAGE_NAME
>
>
>
> and in your email you can call the property $FAILED_STAGE.
> hope it helps
>
>
>
>
> On Fri, 23 Aug 2019 at 12:42, Sureshkumar Ramar <sureshku...@gmail.com> wrote:
>
> Hi,
> i am using jenkins pipeline. i want to send the failed stage name to the developer. is there a way to capture the failure stage in jenkins. it should work in parallel stages also. 
>
>
> --
>
>
> Thanks & Regards,
> Suresh Kumar R
>
>
>
>
> --
>
> 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 jenkins...@googlegroups.com.
>
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAM6nqfeQ9sPjgT-nPf%2BhWDY-nuE30%3D3O6No-10WLT3G%2B-jiPvg%40mail.gmail.com.
>
>
>
>
> --
>
>
>
>
>
> Best Regards / Mit freundlichen Grüßen,
> Faad Sayaou,
> Embedded Systems for Mechatronics Masters student | FH Dortmund | Germany
> Fachhochschule Dortmund
> University of Applied Sciences and Arts
> Email: faad...@gmail.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 jenkins...@googlegroups.com.

David Karr

unread,
Aug 25, 2019, 10:52:59 AM8/25/19
to jenkins...@googlegroups.com
On Fri, Aug 23, 2019 at 3:42 AM Sureshkumar Ramar <sureshku...@gmail.com> wrote:
Hi,
i am using jenkins pipeline. i want to send the failed stage name to the developer. is there a way to capture the failure stage in jenkins. it should work in parallel stages also. 

The basic idea is to define a global variable that holds the current stage name.  At the end of the build, using whatever notification mechanisms you have available, you send that stage name variable in the notification.

You define a global function called something like "mystage" that looks something like this:

     def mystage(String stageName, Closure body) {
         env.GLOBAL_STAGE_NAME = stageName
         stage (stageName) {
         try {
             body()
         } catch (err) {
             env.GLOBAL_STAGE_NAME = stageName
             throw err
         }
     }


Then, for each stage in your pipeline, you use this syntax:

    mystage("name of stage") {
        ...
    }

--
Thanks & Regards,
Suresh Kumar R

--
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.
Reply all
Reply to author
Forward
0 new messages