Jenkins Pipeline sh display name/label

2019-03-10 12:46发布

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

8条回答
疯言疯语
2楼-- · 2019-03-10 13:47

Try this, a good workaround

import org.jenkinsci.plugins.workflow.cps.CpsThread
import org.jenkinsci.plugins.workflow.actions.LabelAction


    def test() {
    def xyz = "Prints PWD"
    try {
        sh script: 'pwd'
    }
    finally {
        CpsThread.current().head.get().addAction(new LabelAction("Shell script ${xyz} "))
    }
}
查看更多
来,给爷笑一个
3楼-- · 2019-03-10 13:47
sh "echo foo", label: "my step"

Doesn't work for me,

It musst be:

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

https://stackoverflow.com/a/54787322/6847446

查看更多
登录 后发表回答