A Jenkins build takes 40 minutes because unit tests, linting and security scans run one after another. How do you speed it up?
BeginnerScenarioJenkins Pipelines and Agents
Answer
Situation read → Independent stages are serialized, so total time is the sum instead of the maximum.
What I'd do →
- Wrap independent stages in
parallel:
stage('Checks') {
parallel {
stage('Unit') { steps { sh 'mvn -q test' } }
stage('Lint') { steps { sh 'npm run lint' } }
stage('SAST') { steps { sh 'semgrep ci' } }
}
}
- Set
failFast trueon the parallel block so one failure stops the rest. - Make sure each branch lands on its own executor.
Why → Wall-clock time drops to the slowest branch, and failures are reported sooner.
Interview tip → Mention that parallelism needs enough executors, otherwise branches just queue.
More on Jenkins Pipelines and Agents
Your team still builds jobs by clicking through Freestyle jobs in the Jenkins UI. A new service is starting. What do you set up instead?BeginnerBuilds queue for 20 minutes during the morning rush, but the Jenkins nodes are mostly idle at night. What do you do?IntermediateA build works on agent A but fails on agent B with "command not found: mvn". How do you stop this class of problem?BeginnerYou need a pipeline to build a branch automatically on push without polling. How do you wire it?BeginnerOnly the main branch should deploy; feature branches and PRs should only build and test. How do you express this?BeginnerA pipeline sometimes hangs forever on a flaky network call and holds an executor. How do you protect the system?Beginner