Is there a way to set the agent label dynamically and not as plain string?
The job has 2 stages:
it might be something about the context of the script block.
this works, using a label of 'docker' in second stage:
def hotLabel = 'docker'
pipeline {
agent { label 'master' }
stages {
stage('Stage1') {
steps {
echo "node_name: ${hotLabel}"
}
}
stage('Stage2') {
agent { label "${hotLabel}" }
steps {
echo "node_name: ${hotLabel}"
}
}
}
}
this does not (gets the same There are no nodes with the label ‘null’ error):
def hotLabel = null
pipeline {
agent { label 'master' }
stages {
stage('Stage1') {
steps {
script {
hotLabel = "docker"
}
}
}
stage('Stage2') {
agent { label "${hotLabel}" }
steps {
echo "node_name: ${hotLabel}"
}
}
}
}