Unit tests, lint, dependency audit and SAST run sequentially and take 22 minutes. How do you restructure the pipeline?
BeginnerScenarioPipeline design & Jenkinsfile decisions
Answer
Situation read → These checks are independent and can run concurrently.
What I'd do →
- Put them under one
parallelstage withfailFast true. - If they share one pod, run them as parallel branches using different containers; if heavy, give each branch its own agent.
- Run the fastest check (lint, under 1 minute) also as a separate first stage so obvious failures stop the build before pods spin up.
stage('Checks') { failFast true; parallel { stage('Unit') { steps { container('node') { sh 'npm test' } } } stage('Audit') { steps { container('node') { sh 'npm audit --audit-level=high' } } } stage('SAST') { steps { container('semgrep') { sh 'semgrep ci' } } } } }
Why → Wall time becomes the slowest branch instead of the sum.
Interview tip → Quote numbers: "22 minutes down to 8, the longest branch".
More on Pipeline design & Jenkinsfile decisions
A team's PR builds pile up: every push to an open PR starts a new 25-minute build while the old one keeps running. What do you change?BeginnerA deploy pipeline waits on `input` for approval, and on Monday you find 14 pods sitting idle since Friday. Fix it.IntermediateDevelopers want to rerun only the deploy stage when it fails due to a flaky cluster API, without rebuilding the image. What do you offer?IntermediateA pipeline must run integration tests against a shared staging database that can only handle one test run at a time across four different repos. How do you coordinate?IntermediateA library must be tested on Node 18, 20 and 22, on Linux and Windows, but Node 18 on Windows is not supported. Design the stage.IntermediateYour 700-line Jenkinsfile now fails with `Method code too large!`. You need a fix today and a plan for next month.Advanced