I have a Jenkins master and pool of slave nodes which dynamically grows and shrinks (based on load). The master node is called "master" and the slaves have guids for names. Currently none of the nodes have labels.
For my project, I want the "develop" branch from github to build on the master node and pull request branches to build on any one of the slaves. This has been working successfully in a scripted pipeline using node('master') and node('!master').
I would like to start using the new Declarative style of pipeline. Is it currently possible to achieve the same "master" and "not master" behaviour in a Declarative Pipeline, based on the branch name?
In the scripted pipeline, it looks like this:
def selectedNode = BRANCH_NAME == 'develop' ? 'master' : '!master'
node(selectedNode) {
}
Thanks
if it works in scripted, you can generally include the exact same contents within a script step in a declarative pipeline. this runs for me:
pipeline {
agent { label 'docker' }
stages {
stage('build') {
steps {
script {
def selectedNode = BRANCH_NAME == 'develop' ? 'master' : '!master'
node(selectedNode) {
}
}
}
}
}
}
i'd probably go this route rather than futzing with the top-level agent declarations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With