Jenkins specifying agent for a particular stage
Running steps with different agents
The syntax of the new pipelines is fairly simple. Below is the example of a working, basic pipeline taken from the documentation itself
pipeline {
agent any
stages {
stage('Example') {
steps {
echo 'Hello World'
}
}
}
post {
always {
echo 'I will always say Hello again!'
}
}
}
One of the strengths introduced in the new pipeline is the specification of the agent
If you would like to execute some stages in a separate node than the others, Define agent none for the pipeline itself, Specify agent after each stage block
pipeline {
agent none
stages {
stage ('Stage 1') {
agent { node 'node-one' }
steps {
echo 'Perform Stage 1 on node-one'
}
}
stage ('Stage 2') {
agent { node 'node-two' }
steps {
echo 'Perform Stage 2 on node-two'
}
}
}
}
We must specify agent none just below pipeline directive. we can of course specify an agent there, but it will mean that this agent becomes the default one for the whole pipeline. we can still perform any step afterward by specifying an agent under the stage. However, in such a case the worker on the node which is specified under pipeline will be occupied until the stage with the separate agent is finished.
Recent Comments
No comments
Leave a Comment
We will be happy to hear what you think about this post