Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Stage name during the build in Jenkins pipeline

Let's say we have the following Jenkinsfile:

stage name: "Cool stage"     sh 'whoami' stage name: "Better stage"     def current_stage = getCurrentStageName()     echo "CONGRATULATIONS, you are on stage: $current_stage" 

The question is how to implement getCurrentStageName(). I know, that I can get an access to build run-time using currentBuild.rawBuild. But how to get stage name from that point?

I need this for some customization in email notifications, so that I can always catch failed stage name and include it into email body.

like image 435
Aleks Avatar asked Apr 08 '16 15:04

Aleks


People also ask

How do I get stage view in Jenkins?

When you run some builds, the stage view will appear with Checkout, Build, and Test columns, and one row per build. When hovering over a stage cell you can click the Logs button to see log messages printed in that stage: after the preceding stage step and before the next one.

What are the stages in your Jenkins pipeline?

It contains a collection of states such as build, deploy, test and release. These jobs or events are interlinked with each other. Every state has its jobs, which work in a sequence called a continuous delivery pipeline.


1 Answers

You can now do this in a built-in manner, since Jenkins 2.3. Like so:

steps {     updateGitlabCommitStatus name: STAGE_NAME, state: 'running'     echo '${STAGE_NAME}' } 

For more information see: https://issues.jenkins-ci.org/browse/JENKINS-44456

like image 111
Jansky Avatar answered Sep 18 '22 21:09

Jansky