0

I'm trying to de-clutter my Jenkins output. Thanks to Is it possible to capture the stdout from the sh DSL command in the pipeline, I know I can send the output of each sh command to a file. However, the commands themselves will still be written to the Jenkins output instead of the file. For example:

sh '''echo "Hello World!"
    ./helloworld
    ./seeyoulater
'''

As is, this results in the Jenkins output looking like this:

echo "Hello World!"
Hello World!
./helloworld
<helloworld output, possibly many lines>
./seeyoulater
<seeyoulater output, possibly many lines>

However, if I send the output to a file, I get Jenkins output like this:

echo "Hello World!" > output.log
./helloworld >> output.log
./seeyoulater >> output.log

and output.log looking like this:

Hello World!
<helloworld output>
<seeyoulater output>

This leads to my Jenkins output being less cluttered, but output.log ends up not having any separators between the script outputs. I suppose I could have echo <command> right before each command, but that just means my Jenkins output gets more cluttered again.

Is there any way to send the entire output of the sh DSL command to a file? Basically something like sh '''<commands here>''' > output.log is what I'm looking for.

Rob Watts
  • 6,866
  • 3
  • 39
  • 58

1 Answers1

0

I wasn't able to find a solution, but I did find a workaround. As mentioned in the sh command documentation, the default is to run using the -xe flags. The -x flag is why the commands are shown in the Jenkins output. The remedy is to add set +x:

sh '''set +x
    echo "Hello World!" > output.log
    ./helloworld >> output.log
    ./seeyoulater >> output.log
'''

The set +x shows up in the Jenkins output, but the rest of the commands do not. From there, it's just a matter of adding enough echo statements in there to make output.log sufficiently readable.

Rob Watts
  • 6,866
  • 3
  • 39
  • 58