Jenkins "script returned exit code 1" in a sh Step
A shell command in an sh step exited with a non-zero status, so Jenkins marked the step and stage as failed.
What this error means
A stage prints command output, then ends with "ERROR: script returned exit code 1". The real cause is in the command output just above the error line.
jenkins
+ npm run build
npm ERR! Missing script: "build"
ERROR: script returned exit code 1Common causes
The command itself failed
A test, build, or lint command returned non-zero; Jenkins only reports the exit code, not the underlying reason.
A pipe or subcommand failed
With set -e or pipefail, an early failure in a chain aborts the whole sh step.
Missing tool or file
The command, script, or file referenced does not exist on the agent.
How to fix it
Read the output above the exit line
- Scroll up from the exit-code line to the actual command error.
- Reproduce the command locally to confirm the fix.
Capture status without failing when expected
- Use returnStatus to handle expected non-zero exits instead of aborting.
- Add diagnostics around the failing command.
Jenkinsfile
def rc = sh(script: 'make test', returnStatus: true)
if (rc != 0) { echo "tests failed with ${rc}" }How to prevent it
- Fail fast on the specific failing command and surface its real error in logs rather than treating exit code 1 as the root cause.
Related guides
Jenkins "FATAL: command execution failed"Fix the Jenkins "FATAL: command execution failed" error where remoting could not run a command on the agent,…
Jenkins "stage" Has No Steps Declarative Pipeline ErrorFix the Jenkins declarative pipeline error where a stage is missing a steps block, which Jenkins rejects at v…
Jenkins "Timeout has been exceeded" Pipeline AbortedFix the Jenkins "Timeout has been exceeded" error where a timeout step or wrapper aborted the build because a…