Pipeline: The sh step does not show all output

383 views
Skip to first unread message

Sverre Moe

unread,
May 27, 2019, 6:20:17 AM5/27/19
to Jenkins Users
The standard output from the sh-step does not show all the output:
final def output = sh(returnStdout: true, label: "Build and Package", script: "make")
writeFile
(file: 'buildOutputFile.txt', text: output)

The Blue Ocean log output from a single Node shows all the warnings, but the output from the sh step does not:

Could it be that the actual output is not stdout, but stderr? Unfortunately sh does not have an returnStderr.

I am using this output for the Warnings Plugin, since I want warning for each build node, and the plugin default reads the entire console output.
recordIssues(tools: [gcc4(id: "gcc-${buildHost}", name: "${buildHost}", pattern: "buildOutputFile.txt")])

Sverre Moe

unread,
May 27, 2019, 6:51:53 AM5/27/19
to Jenkins Users
I found a way to ouput both stdout and stderr, but then I didn't get either in Jenkins Console.
sh("make 2>&1 | tee buildOutputFile.txt")

Ullrich Hafner

unread,
May 27, 2019, 6:57:28 AM5/27/19
to Jenkins Users
Would a workaround as shown in https://issues.jenkins-ci.org/browse/JENKINS-54832 help?

-- 
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/5efbb0ab-54e9-462c-86f6-2ff0593a88fa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sverre Moe

unread,
May 27, 2019, 9:50:07 AM5/27/19
to Jenkins Users
Not sure I understand that workaround.

(((("$@" 2>&1; echo $? >&3) | tee "$LOGFILE" >&4) 3>&1) | (read xs; exit $xs)) 4>&1

I tried to modify this to work with my example:

final def output = sh(returnStdout: true, script: "((((make >&3) | tee buildOutput.txt >&4) 3>&1) | (read xs; exit $xs)) 4>&1")

Not quite sure how!

mandag 27. mai 2019 12.57.28 UTC+2 skrev Ullrich Hafner følgende:
Would a workaround as shown in https://issues.jenkins-ci.org/browse/JENKINS-54832 help?
Am 27.05.2019 um 12:51 schrieb Sverre Moe <sver...@gmail.com>:

I found a way to ouput both stdout and stderr, but then I didn't get either in Jenkins Console.
sh("make 2>&1 | tee buildOutputFile.txt")

mandag 27. mai 2019 12.20.17 UTC+2 skrev Sverre Moe følgende:
The standard output from the sh-step does not show all the output:
final def output = sh(returnStdout: true, label: "Build and Package", script: "make")
writeFile
(file: 'buildOutputFile.txt', text: output)

The Blue Ocean log output from a single Node shows all the warnings, but the output from the sh step does not:

Could it be that the actual output is not stdout, but stderr? Unfortunately sh does not have an returnStderr.

I am using this output for the Warnings Plugin, since I want warning for each build node, and the plugin default reads the entire console output.
recordIssues(tools: [gcc4(id: "gcc-${buildHost}", name: "${buildHost}", pattern: "buildOutputFile.txt")])

-- 
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsub...@googlegroups.com.

Sverre Moe

unread,
May 27, 2019, 10:27:11 AM5/27/19
to Jenkins Users
I got it to work by modifying my original sh step. I had to remove returnStdout

sh(label: "Build and Package", script: "make 2>&1 | tee buildOutputFile.txt")

Sverre Moe

unread,
May 31, 2019, 4:06:05 AM5/31/19
to Jenkins Users
This workaround gave me some problem with failing builds.
The step no longer is marked failed when it fails.

Baptiste Mathus

unread,
May 31, 2019, 7:41:50 AM5/31/19
to jenkins...@googlegroups.com
Likely because when calling scripts this way, `set -o pipefail` is not set maybe?

To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/1af99929-9178-4181-8d54-9ab38b79a2d7%40googlegroups.com.

Sverre Moe

unread,
May 31, 2019, 7:50:23 AM5/31/19
to Jenkins Users
I did not set such a parameter

Like so?
sh("set -o pipefail\n commandA | commandB")


fredag 31. mai 2019 13.41.50 UTC+2 skrev Baptiste Mathus følgende:
Likely because when calling scripts this way, `set -o pipefail` is not set maybe?

To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkins...@googlegroups.com.

Sverre Moe

unread,
May 31, 2019, 8:11:41 AM5/31/19
to Jenkins Users
Tried various solutions.
Settled with this which works:

sh(label: "Build and Package", script:
"""
    set -o pipefail

    make 2>&1 | tee buildOutputFile.txt
"""
)

Daniel Saier

unread,
May 31, 2019, 12:20:28 PM5/31/19
to Jenkins Users
You can also use the tee step, which automatically propagates the return codes of the steps inside of the tee.

Sverre Moe

unread,
May 31, 2019, 5:51:25 PM5/31/19
to Jenkins Users
Marvelous, thanks, I'll try that.
Reply all
Reply to author
Forward
0 new messages