When the pipeline breaks

Jenkins CI/CD Course · lesson 14 of 15 · 5 min read

The common Jenkins failures have specific causes, and Replay plus the linter find most of them in minutes.

Open this lesson in the learning hub

Key points

  • Replay re-runs the last build with an edited script and no commit, which is the fastest way to bisect Groovy.
  • The declarative linter validates a Jenkinsfile before you push, over the CLI or a POST to the validate endpoint.
  • A NotSerializableException means a value that cannot be serialised stayed alive across a pipeline step.
  • Mark a helper @NonCPS when it touches such objects, and never call pipeline steps from inside it.
  • A build stuck in the queue almost always means no online agent carries the label the stage asked for.
  • A failing sh aborts the stage, so pass returnStatus: true when a non-zero exit is expected.

Example

# Validate a Jenkinsfile before pushing it
curl -X POST -F "jenkinsfile=<Jenkinsfile" \
     https://jenkins.example.com/pipeline-model-converter/validate

# Same check over the CLI, using an SSH key already known to Jenkins
ssh -p 2222 jenkins.example.com declarative-linter < Jenkinsfile

# Expected shell failures: read the code instead of aborting
# status = sh(script: './check.sh', returnStatus: true)

Read the failing stage log first, name the cause, then prove the fix with Replay before you commit it.

This is a reading copy. The full lesson — with the visual explainer, the interactive lab and a Run button for the code — lives in the Jenkins CI/CD Course course, and every lesson in it is listed on the Jenkins CI/CD Course contents page.