I'm using Jenkins ver. 2.107.1 and I created a Node. See the screenshot below for the configuration details of the Node.
#!/bin/sh
I=$1
P=...
Z=...
# According to `gcloud compute instances start --help` this is sync.
gcloud compute --project $P instances start --zone $Z $I || exit 1
finish() {
# Shutdown.
echo 3 >> /tmp/x
gcloud compute --project $P instances stop --zone $Z $I >> /tmp/x
}
trap finish EXIT
# "What Jenkins expects from your script is that, in the end, it has to execute
# the agent program like java -jar agent.jar, on the right computer, and have
# its stdin/stdout connect to your script's stdin/stdout."
echo 1 >> /tmp/x
gcloud compute --project $P ssh --zone $Z $I --command 'wget "http://10.132.0.20:8080/jnlpJars/agent.jar" -O agent.jar && java -jar agent.jar'
echo 2 >> /tmp/x
Connection terminated channel stopped[04/10/18 13:13:47] Launching agent $ /var/lib/jenkins/start-worker.sh instance-eval-worker-template + I=instance-eval-worker-template + P=... + Z=... + gcloud compute --project ... instances start --zone ... instance-eval-worker-templateStarting instance(s) instance-eval-worker-template....done. Updated [https://www.googleapis.com/compute/v1/projects/.../instances/instance-eval-worker-template]. + trap finish EXIT + echo 1 + gcloud compute --project ... ssh --zone ... instance-eval-worker-template --command wget "http://10.132.0.20:8080/jnlpJars/agent.jar" -O agent.jar && java -jar agent.jarUpdating project ssh metadata........................failed.--2018-04-10 13:14:14-- http://10.132.0.20:8080/jnlpJars/agent.jar Connecting to 10.132.0.20:8080... connected. HTTP request sent, awaiting response... 200 OK Length: 762466 (745K) [application/java-archive] Saving to: ‘agent.jar’ 0K .......... .......... .......... .......... .......... 6% 102M 0s 700K .......... .......... .......... .......... .... 100% 206M=0.006s 2018-04-10 13:14:14 (131 MB/s) - ‘agent.jar’ saved [762466/762466] <===[JENKINS REMOTING CAPACITY]===>channel started Remoting version: 3.17 This is a Unix agent Evacuated stdout
Agent successfully connected and online
Connection terminated