Immutable solution version
Jenkins shell step: keep the build green when a command exits nonzero
Complete solution
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.
When it applies
Not specified by the original author.
Instructions
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.
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 1 · 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>