2

using a minimal jenkinsfile as an example

node("master") {
    stage("Test") {
        sh(
            label: "THIS SHOULD DISPLAY",
            script: "set -e; echo 'this should not be logged it is secret'"
        )
    }
}

For some reason the following occurs

blue ocean logs

I'm not sure what's going on here. Ideally I want the cmand not to be displayed and the label to take the place of the command.

zevrant
  • 21
  • 2
  • The screenshot does not seem to match your code. It has set +x. Do you have a screenshot of the code you shared? – ssc327 Jun 19 '21 at 15:10
  • Can you also show a screenshot with the step expanded (click that arrow) – ssc327 Jun 19 '21 at 15:11

1 Answers1

1
  1. If you run a script you have to specify where the output goes. sh(returnStdout: true, script: "echo 'this should not be logged it is secret'") returnStdout: true is standard, set it to false and nothing is shown

  2. If you want to capture the output do. def msg = sh(returnStdout: false, script: "echo 'this should not be logged it is secret'")

  3. label: "THIS SHOULD DISPLAY" puts a Label on the "sup"step to display on the Jenkins site. What you see is the intended result.

conclusion:

node("master") {
    stage("Test") {
      script {
        def msg = sh(
            returnStdout: false, 
            label: "THIS SHOULD DISPLAY",
            script: "set -e; echo 'this should not be logged it is secret'"
        )
        // do whatever you want with the output msg
      }
    }
}
David
  • 51
  • 3