Hide command executed, only show output

前提是你 提交于 2020-05-23 08:03:47

问题


I want to hide jenkins sh execute command in pipeline

pipeline {
    agent any

    stages {
        stage('Load Lib') {
            steps {
                sh "ls -al /"
            }
        }
    }
}

Current result:

[Pipeline] {
[Pipeline] stage
[Pipeline] { (Load Lib)
[Pipeline] sh
[Test] Running shell script
+ ls -al /

I want to hide Running shell script ls -al / command in output.

Please help


回答1:


This is definitely related to Echo off in Jenkins Console Output

For pipeline, what this means is:

pipeline {
    agent any

    stages {
        stage('Load Lib') {
            steps {
                sh '''
                    set +x
                    s -al
                    set -x 
                '''
            }
        }
    }
}

''' indicates a multi line command. set +x turns off command echoing, and set -x turns it back on again.




回答2:


You can override this behaviour for the whole script by putting the following at the top of the build step:

#!/bin/bash +x


来源:https://stackoverflow.com/questions/47523909/hide-command-executed-only-show-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!