Speed Up Jenkins Pipelines with Declarative Parallel Stages
Learn how to use Jenkins Declarative Pipeline parallel stages to cut build times, see a concrete example, and understand the resource trade‑offs.
11 Jul 2025, 22:40 UTC

Problem: Long pipeline times when independent steps run sequentially
Many teams notice that a Jenkins pipeline spends minutes waiting for steps that could run at the same time—building artifacts, running unit tests, and pulling Docker images are often independent but are executed one after another. This serial execution inflates feedback cycles and wastes available executors.
Thesis: Declarative Pipeline’s parallel stages let you run independent stage blocks on separate executors, cutting wall‑clock time without rewriting the whole pipeline.
How parallel stages work
The parallel directive lives inside a stage. Each branch declared with stage gets its own executor (subject to the agent’s executor pool). Jenkins schedules the branches concurrently; if the pool is smaller than the number of branches, excess branches wait in the queue. Options such as timeout, retry, and environment apply per branch, giving fine‑grained control.
Worked example: two sleep stages
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building…'
}
}
stage('Tests') {
parallel {
stage('Unit') {
steps {
sleep 30
}
}
stage('Integration') {
steps {
sleep 30
}
}
}
}
}
}
To try this:
- Create a new Pipeline job and paste the Jenkinsfile above.
- Ensure the Jenkins controller or the agent labeled
anyhas at least two free executors (Manage Nodes → Configure → # of executors). - Run the job and watch the Build Executor Status widget; you should see two executors busy simultaneously.
- When the build finishes, the total elapsed time should be close to 30 seconds (the length of the longest branch) rather than 60 seconds.
- Open the raw console log (
$JENKINS_HOME/jobs//builds//log) and notice lines prefixed with[Parallel Stage: Unit]and[Parallel Stage: Integration]interleaved, confirming concurrent execution.
Trade‑off and limitation
While parallel stages reduce latency, they consume executor resources proportional to the number of branches. Declaring more parallel stages than available executors causes Jenkins to queue the excess branches, which can increase overall wait time and, on heavily loaded masters, lead to out‑of‑memory conditions if each branch holds large objects in memory. Deeply nested parallel blocks also flatten in the Blue Ocean view, making it harder to trace which console output belongs to which branch without inspecting the raw log.
Actionable closing
- Start small: add parallelism only to stages that are truly independent and short‑lived.
- Monitor executor usage via the Build Executor Status widget or the
/computer/api/jsonendpoint. - If you regularly need more parallelism, consider scaling out agents (static slaves, Docker cloud, or Kubernetes plugin) so the executor pool matches your peak parallelism.
- Document the expected executor count in the job description so future maintainers know the resource assumption.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.