I have a Jenkins pipeline and I am trying to get the NODE_NAME of the nested NODE that I switch to. Example:
@Library('git lib that we use')
import org.our_git_lib.*
import java.text.SimpleDateFormat
node("master") {
stage("Do something") {
// do something on master
}
// switch to new node to do some stuff
node("new_node_label") {
stage("do something") {
echo env.NODE_NAME // This echos master NOT the new_node_label name
}
stage("do something") {
// do something in new_node
}
}
}
The NODE_NAME environment variable is not updated to the new_node_label's node name. How do I get the current node name of the node that is running. In my console output, I do see
Running on nested_node_name in /var/jenkins
Where the name is being displayed, but I can't actually get that new nested_node_name in a variable. How do I do that?
Thanks in advance.