22

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
  • 361
  • 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

24

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
                    //commands to be echoed off
                    ls -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,733
  • 3
  • 27
  • 45
  • 2
    If you need to interpolate ${VARIABLE}s, you can substitute a triple double quote: """ –  Apr 08 '19 at 15:22
  • 3
    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
  • 69,000
  • 34
  • 174
  • 243