What I'm trying to achieve here to run multiple stages in same node which will get captured in initial stage, then will be used by some of the following stages as required.
Below is the sample Jenkinsfile:
pipeline {
agent {
label 'redhat_linux'
}
stages {
stage('build') {
options {
timeout(time: 100, unit: 'SECONDS')
}
input {
message "Should we continue?"
ok "Yes, we should."
submitter "user1,user2"
parameters {
string(name: 'PERSON', defaultValue: 'Mr Jenkins', description: 'Who should I say hello to?')
}
}
steps {
script{
agentName = "${NODE_NAME}"
echo "The node name is :: ${agentName}"
}
sh 'pwd;ls -ltr'
}
}
stage("promote"){
agent{
node {
label "${agentName}"
}
}
steps{
script{
echo "The node name is :: ${agentName}"
}
sh 'echo "This is a promote step " '
}
}
}
}
I'm facing following error:
groovy.lang.MissingPropertyException: No such property: agentName for class: groovy.lang.Binding
I did tried solution from below link, but it didn't work.
In a declarative jenkins pipeline - can I set the agent label dynamically?
Jenkins version: CloudBees Jenkins Enterprise 2.121.3.1