How to disable command output in jenkins pipeline build logs

I am using Jenkinsfile for pipeline scripting.

Is there a way to disable the printing of shell commands in assembly logs?

Here is just a simple jenkins project example:

node{ stage ("Example") { sh('echo shellscript.sh arg1 arg2') sh('echo shellscript.sh arg3 arg4') } } 

which produces the following output in the console log:

 [Pipeline] node Running on master in /var/lib/jenkins/workspace/testpipeline [Pipeline] { [Pipeline] stage [Pipeline] { (Test) [Pipeline] sh [testpipeline] Running shell script + echo shellscript.sh arg1 arg2 shellscript.sh arg1 arg2 [Pipeline] sh [testpipeline] Running shell script + echo shellscript.sh arg3 arg4 shellscript.sh arg3 arg4 [Pipeline] } [Pipeline] // stage [Pipeline] } [Pipeline] // node [Pipeline] End of Pipeline Finished: SUCCESS 

Basically, I would like to disable printing of the commands themselves.

 + echo shellscript.sh arg1 arg2 + echo shellscript.sh arg3 arg4 
+6
source share
1 answer

By default, Jenkins runs shell scripts with the -xe flags. -x provides additional registration. -e makes the script exit if any command inside returns a non-zero exit status. To reset the flag, I would suggest two options:

  • Call set +x in the body of your script.
  • Pass custom shebang line without -x : sh('#!/bin/sh -e\n' + 'echo shellscript.sh arg1 arg2')

As for the second option, you can define a wrapper function for convenience, which will add a script to the custom shebang and then call sh

 def mysh(cmd) { sh('#!/bin/sh -e\n' + cmd) } 
+18
source

All Articles