How to place a condition in node for select an agent master or stage?
def curNode = "${env.Environment}"
node(curNode === 'prod' ? 'master' : 'stage') { <= "error this"
try {
dir(env.Environment) {
stage("Clone repository") {
echo "clong success"
}
}
} catch (e) {
echo 'Error occurred during build process!'
echo e.toString()
currentBuild.result = 'FAILURE'
}
}
CodePudding user response:
If you need to compare two strings, you need to use ==
. When you use ===
it checked whether the objects are identical. Hence update your Script like the below.
def curNode = "${env.Environment}"
node(curNode == 'prod' ? 'master' : 'stage') { <= "error this"
try {
dir(env.Environment) {
stage("Clone repository") {
echo "clong success"
}
}
} catch (e) {
echo 'Error occurred during build process!'
echo e.toString()
currentBuild.result = 'FAILURE'
}
}