-
Notifications
You must be signed in to change notification settings - Fork 248
Parallelism
How to use parallel
and why (e.g. for running the same tests over multiple browser platforms)
You can use parallelism inside pipelines for a few reasons:
- Split up a test suite on a powerful machine
- Run tests across different operating systems or environments
- Distribute work across a cluster
The aim of all this is to shorten the length of the pipeline run.
In this case, we will split our tests into two:
pipeline {
agent { label '' }
stages {
stage("test") {
steps {
parallel (
"Firefox" : {
sh "echo testing FFX"
sh "echo more steps"
},
"Chrome" : {
sh "echo testing Chrome"
sh "echo more steps"
}
}
)
}
}
}
This makes use of one single agent, and spins off 2 runs of the steps inside each parallel branch, as separate processes.
The steps:
sh "echo testing FFX"
sh "echo more steps"
Are run at the same time as:
sh "echo testing Chrome"
sh "echo more steps"
Let's run steps on different platforms at the same time:
pipeline {
agent none
stages {
stage("distribute") {
steps {
parallel (
"windows" : {
node('windows') {
bat "print from windows"
}
},
"mac" : {
node('osx') {
sh "echo from mac"
}
},
"linux" : {
node('linux') {
sh "echo from linux"
}
}
}
)
}
}
}
The key difference here is that there is image none
and then in each parallel section, we use node
to go and fetch an agent that suits, and run steps on it remotely.
You don't have to use different node
labels. You can use the same one as many times as you like and Jenkins will try to schedule the work on free agents that are suitable:
"Browser Testing" : {
node('linux') {
sh "echo browser testing"
}
},
"Unit Testing" : {
node('linux') {
sh "echo unit testing"
}
}
There is a lot more you can do with parallelism, but this is a start.
Note that parallelism happens inside a running pipeline - you can also have multiple instances of a pipeline running concurrently, even if you don't use parallel
.
Documentation
- Getting Started
- Running multiple steps
- Controlling your build environment
- Environment variables
- Reporting test results and storing artifacts
- Notifications
- Deployment and credentials
- Parallelism
- Triggering runs
- Parametrized pipelines
- Pipeline options and log rotation
- Jenkinsfile validation from the CLI
- Advanced pipeline authoring
- Syntax reference
- Version history and changes
Examples