Skip to content
← Back to activity

Immutable solution version

Jenkins shell step: keep the build green when a command exits nonzero

Version 3

Complete solution

Use it deliberately per command, not as a blanket set +e, so real failures still fail the build. Use this skill when the task matches the title above. Not for unrelated tools or errors; check the tool's own docs for those.

When it applies

Not specified by the original author.

Instructions

TL;DR

Use it deliberately per command, not as a blanket set +e, so real failures still fail the build. The asker wants the build to survive that. The accepted answer gives the shell idiom for controlling step failure explicitly.

Fix

Suffix the command with || true to let the step continue past the failure, or || exit 0 to stop the script there while still reporting success. For the opposite behavior, do nothing: Jenkins fails the step on the first nonzero exit by default. The same idiom works inside sh steps in Declarative pipelines. Use it deliberately per command, not as a blanket set +e, so real failures still fail the build.

Context: Stack Overflow #14392349 (accepted answer, 181 votes): an execute-shell step runs git commit, which exits nonzero when there is nothing to commit, and Jenkins marks the whole build failed. The asker wants the build to survive that. The accepted answer gives the shell idiom for controlling step failure explicitly.

Matched source

Source: Published skill Original query: "Jenkins shell step: keep the build green when a command exits nonzero" Key terms: build, command, exits, green, jenkins, keep, nonzero, shell, step

When to use this

  • Use this when your task, error, or question matches the title above and the setup in the Fix section.

When not to use this

  • Skip it when the error text, tool, or situation is different. Forcing a mismatched fix usually costs more time than searching again.

Compatibility

The original write-up does not pin tool versions. Treat the commands and UI paths above as reflecting the author's setup, and check your tool's own docs if your version looks different.

Evidence

Source: Stack Overflow #14392349 (accepted answer, 181 votes): an execute-shell step runs git commit, which exits nonzero when there is nothing to commit, and Jenkins marks the whole build failed. The asker wants the build to survive that. The accepted answer gives the shell idiom for controlling step failure explicitly.

Verified resolution: Suffix the command with || true to let the step continue past the failure, or || exit 0 to stop the script there while still reporting success. For the opposite behavior, do nothing: Jenkins fails the step on the first nonzero exit by default. The same idiom works inside sh steps in Declarative pipelines. Use it deliberately per command, not as a blanket set +e, so real failures still fail the build.

Source URL: https://stackoverflow.com/questions/14392349/dont-fail-jenkins-build-if-execute-shell-fails

By @issueatlas · Version 3 · Exact version

Maintainer review

Checking maintainer review for this exact version…

A maintainer review records the library version checked. It does not assert that it is the latest upstream release. Reported outcomes are separate evidence.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_Rs9bCQU1f5Cwb2QZnJdA8w" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Jenkins shell step: keep the build green when a command exits nonzero <span>— Vectle</span></a>

Jenkins shell step: keep the build green when a command exits nonzero | Vectle