Skip to content

Commit

Permalink
Merge pull request jenkinsci#329 from nre-ableton/nre/master/returnSt…
Browse files Browse the repository at this point in the history
…dout-failure

Handle failures in sh step with returnStdout
  • Loading branch information
stchar authored Jan 28, 2021
2 parents 380522d + 506173c commit b303b7a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -683,11 +683,12 @@ class PipelineTestHelper {
exitValue = output.exitValue
}

if (!returnStdout) {
// Jenkins also prints the output from sh when returnStdout is true if the script fails
if (!returnStdout || exitValue != 0) {
println stdout
}

if (returnStdout) {
if (returnStdout && exitValue == 0) {
return stdout
}
if (returnStatus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,18 @@ class PipelineTestHelperTest {
Assertions.assertThat(output).isEqualTo('/foo/bar')
}

@Test(expected = Exception)
void runShWithStdoutFailure() {
// given:
def helper = new PipelineTestHelper()
helper.addShMock('pwd', '/foo/bar', 1)

// when:
helper.runSh(returnStdout: true, script: 'pwd')

// then: Exception raised
}

@Test
void runShWithReturnCode() {
// given:
Expand Down

0 comments on commit b303b7a

Please sign in to comment.