We use the EC2 Metadata API to retrieve the local host IP. Creating a new URL() object and getting the text from the result showed that it was running on the queueing machine. Fair enough, understandable for the groovy script to initially get executed on that one first.
However, I then installed the httpRequest plugin, hoping that it would solve that problem. Nope.
sh "curl -s http:
sh "curl -s http:
def nodePublicIP = readFile('public.txt')
def nodePrivateIP = readFile('private.txt')
sh "rm public.txt"
sh "rm private.txt"
def httpRequestPublicIP = httpRequest("http:).content
def httpRequestPrivateIP = httpRequest("http:).content
println "Running on host $nodePublicIP ($nodePrivateIP)"
println "httpRequest says host $httpRequestPublicIP ($httpRequestPrivateIP)"
Output:
[Pipeline] echo
Running on host <node public IP> (<node private IP>)
[Pipeline] echo
httpRequest says host <Jenkins master public IP> (<Jenkins master private IP>)