I've been using a Jenkins pipeline with a parallel step for testing like this:
pipeline {
agent { label 'php' }
stages {
stage('build') {
steps {
...
}
}
stage('test') {
parallel {
stage('unit tests') {
steps {
...
}
}
stage('integration tests') {
steps {
...
}
}
}
}
stage('deploy') {
steps {
...
}
}
}
}
The pipeline runs fine on a single agent, but now I want to add a step with manual input, which should not keep the agent running. The agents are cloud servers that get started and stopped on demand.
To do so, I assigned "none" agent to the pipeline and the actual agent to all stages but the one requesting input:
pipeline {
agent none
stages {
stage('build') {
agent { label 'php' }
steps {
...
}
}
stage('test') {
parallel {
stage('unit tests') {
agent { label 'php' }
steps {
...
}
}
stage('integration tests') {
agent { label 'php' }
steps {
...
}
}
}
}
stage('deploy staging') {
agent { label 'php' }
steps {
...
}
}
stage('confirm release') {
steps {
input { message 'release?' }
}
}
stage('deploy production') {
agent { label 'php' }
steps {
...
}
}
}
}
Artifacts that are needed in a following stage are carried over with stash
and unstash
. This works, but with two nuisances:
- Stashing and unstashing between each single stage causes overhead. I would rather have all stages until the manual input executed in a single workspace. But
agent
is only allowed in stages that contain steps. - Each parallel stage blocks a single agent. So if there is only one free agent, there is no parallel execution, unlike before.
I can live with (1) if it's not possible otherwise, but parallel execution on one agent is important for me. Is it possible somehow in my current setup? If not, what are my options to achieve something similar?