What does `retry`, `timeout` and `catchError` do in a pipeline?
IntermediateConceptJenkins
Answer
retry(n) re-runs the enclosed steps up to n times on failure (good for flaky network steps, not for hiding flaky tests). timeout aborts the enclosed block when time runs out. catchError lets a failure mark the build as FAILURE or UNSTABLE while the pipeline keeps going, useful for optional steps.
retry(3) { sh 'curl -fsS https://registry.example.com/healthz' }
catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') {
sh './optional-scan.sh'
}
More on Jenkins
What is Jenkins and how is its architecture organised?BeginnerWhat are executors, nodes and labels in Jenkins?IntermediateWhy should you not run builds on the Jenkins controller?BeginnerHow do inbound (JNLP/WebSocket) and SSH agents connect to the controller?IntermediateWhat is a Jenkinsfile and where does it live?BeginnerDeclarative versus Scripted Pipeline: what are the differences?Intermediate