18

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

Binh Pham
  • 311
  • 1
  • 2
  • 7
  • 1
    Possible duplicate of [Echo off in Jenkins Console Output](https://stackoverflow.com/questions/26797219/echo-off-in-jenkins-console-output) – Bono May 15 '18 at 08:28

2 Answers2

20

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.

Ben Green
  • 3,623
  • 2
  • 26
  • 43
  • 2
    If you need to interpolate ${VARIABLE}s, you can substitute a triple double quote: """ –  Apr 08 '19 at 15:22
  • 2
    This is just excluding command from console, but If I hover on Jenkins Pipeline stage log from UI, then it still shows command – Alpesh Jikadra Jan 27 '21 at 13:37
0

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

#!/bin/bash +x
Eric Aya
  • 68,765
  • 33
  • 165
  • 232