How to disable command output in jenkins pipeline build logs How to disable command output in jenkins pipeline build logs jenkins jenkins

How to disable command output in jenkins pipeline build logs


By default Jenkins starts shell scripts with flags -xe. -x enables additional logging. -e makes the script exit if any command inside returns non-zero exit status. To reset a flag I'd suggest two options:

  1. Call set +x in the body of your script.
  2. 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 prepend the script with custom shebang and then call sh

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


For instances where post processing is required. I extended the original solution provided here.

For example

def output = printWithNoTrace("ping -c 1 $FQDN | grep PING).trim()

wrapper function

def printWithNoTrace(cmd) {steps.sh (script: '#!/bin/sh -e\n'+ cmd,returnStdout: true)        }

The shell output is returned to trim() and saved to "output"