Accelerate Jenkins Builds with Declarative Parallel Stages
Learn how to cut Jenkins build times by declaring independent stages inside a parallel block of a Declarative Pipeline, with prerequisites, a step‑by‑step example, verification tips, and recovery strategies.
27 Nov 2025, 20:35 UTC

Desired outcome
Reduce total build time by running independent stages simultaneously on different agents. When stages are declared inside a parallel block, Jenkins schedules each branch on an available executor that matches the specified label, so the overall duration approaches the longest parallel branch rather than the sum of all branches.
Prerequisites
- Jenkins 2.263+ LTS with the Pipeline plugin version 2.6 or newer installed.
- At least two agents (nodes) that are online and have free executors; each agent should be identified by a distinct label (e.g.,
linux-large,windows-build). - Permission to edit the repository's Jenkinsfile and to trigger a build in Jenkins.
- Basic familiarity with Declarative Pipeline syntax.
Focused procedure
- Identify independent work – Determine which stages do not depend on each other’s artifacts or side‑effects (e.g., unit tests, integration tests, static analysis).
- Select agent labels – Choose labels that match the agents you want to use for each parallel branch. Ensure the labels are unique across branches if you intend to isolate workspaces.
- Edit the Jenkinsfile – Add a top‑level
agent(or keep the existing one) and wrap the chosen stages in aparallelblock. Inside each branch, specify anagent { label 'YOUR_LABEL' }section. - Commit and push – Save the updated Jenkinsfile to the source control branch that Jenkins monitors.
- Trigger a build – Start a new pipeline run (via UI, webhook, or CLI) and observe the execution.
Example Jenkinsfile snippet
pipeline { agent { label 'linux-large' } stages { stage('Build') { steps { sh 'make' } } stage('Tests') { parallel { stage('Unit Tests') { agent { label 'linux-large' } steps { sh './run-unit-tests.sh' } } stage('Integration Tests') { agent { label 'linux-large' } steps { sh './run-integration-tests.sh' } } stage('Static Analysis') { agent { label 'linux-large' } steps { sh './run-static-analysis.sh' } } } } stage('Deploy') { agent { label 'linux-large' } steps { sh './deploy.sh' } } } }Replace
linux-largewith the actual label of your agents. If you have heterogeneous agents, assign different labels to each parallel branch as needed.Expected checks
- After the build starts, open the Stage View or Blue Ocean UI for that run.
- Confirm that the start timestamps of the parallel stages overlap (they should begin within a few seconds of each other).
- Check the timing of each branch; the total pipeline duration should be close to the duration of the longest single branch, not the sum of all branch durations.
- If using Blue Ocean, verify that the parallel branches are displayed side‑by‑side and that no branch shows a waiting executor icon for an extended period.
Recovery options
- Post‑failure handling – Add a
post { failure { ... } }block at the pipeline or stage level to retry the failing branch, send notifications, or mark the build unstable. - Manual rerun – Use the Replay action on a completed build to modify and re‑execute only the failed stage without changing the repository.
- Agent starvation mitigation – Monitor executor usage on the involved agents; if queues appear, add more executors or adjust labels to better distribute load.
- Workspace isolation – Ensure each parallel stage works in its own directory (the default) or explicitly use
dir('…')to avoid unintended file clashes.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.