Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Pipeline sh display name/label

With Jenkins 2 Pipeline plugin, there's a useful feature allowing a quick overview of the pipeline stages and status of steps, including logging output.

However, if you use the "Shell script" (sh) step, there doesn't seem to be a way to label that script with a useful name, so the display merely shows a long list of "Shell Script" (shown in the image below).

How can I assign a useful name, or how can I use some other step to accomplish the same effect?

enter image description here

like image 807
goofballLogic Avatar asked Sep 09 '16 15:09

goofballLogic


People also ask

What is sh label?

sh : Shell ScriptLabel to be displayed in the pipeline step view and blue ocean details for the step instead of the step type. So the view is more meaningful and domain specific instead of technical. returnStatus : boolean (optional)

What is label in Jenkins pipeline?

label. Execute the Pipeline, or stage, on an agent available in the Jenkins environment with the provided label. For example: agent { label 'my-defined-label' } Label conditions can also be used.

What is sh command in Jenkins pipeline?

On Linux, BSD, and Mac OS (Unix-like) systems, the sh step is used to execute a shell command in a Pipeline. Jenkinsfile (Declarative Pipeline) pipeline { agent any stages { stage('Build') { steps { sh 'echo "Hello World"' sh ''' echo "Multiline shell steps works too" ls -lah ''' } } } }


2 Answers

Update Feb 2019:

According to gertvdijk's answer below, it is now possible to assign an optional label to the sh step, starting from v2.28, and for those who can't upgrade yet, there's also a workaround. Please check his answer for details and comments!


Previous version (hover to see it):

As far as I know, that's currently not possible. In the Jenkins tracker, there is a Name or alias Shell Script Step (sh) issue which is similar to your situation:

The sh step adds a "Shell Script" step in the Pipeline. However, there could be multiple such steps including steps from various plugins (e.g., Docker), which makes it hard to distinguish the steps. We should perhaps add an optional parameter to sh to specify a name or alias which would then appear in the pipeline steps. e.g., the following can be the step for npm which would show as "Shell script: npm" in the pipeline view.

sh cmd:"npm install", name: "npm"
However, it was closed as a duplicate of the older Allow stage to operate as a labelled block which has been fixed recently and seems to be included in v2.2 of the pipeline-stage-step-plugin (see changelog).

It seems that stages can now be nested and they will appear in the view table, but I don't think it's what you're looking for.
like image 178
Morfic Avatar answered Sep 21 '22 06:09

Morfic


Version 2.28+ of the "Pipeline Nodes and Processes Plugin" has gained the label option for the sh step now with JENKINS-55410:

label (optional)

Label to be displayed in the pipeline step view and blue ocean details for the step instead of the step type. So the view is more meaningful and domain specific instead of technical.

  • Type: String

E.g.:

sh script: "echo foo", label: "my step" 

If you can't upgrade yet, another option is to use the Labelled Pipeline Steps plugin.

like image 33
gertvdijk Avatar answered Sep 22 '22 06:09

gertvdijk