Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle failures in sh step with returnStdout #329

Merged
merged 2 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
nre-ableton marked this conversation as resolved.
Show resolved Hide resolved
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