title: Get running build status on a given Jenkins worker node
body: <p>I'm trying to setup some automation for gracefully removing a worker node in Jenkins. Currently I can do the following to get a node to stop accepting new jobs:</p>
  
  <pre><code>  JENKINS_CRUMB=$(curl -v -c /tmp/cookie -u "$user:$pass" "$JENKINS_URL/crumbIssuer/api/json" | jq -r '.crumb')
    echo "CSFR Token: $JENKINS_CRUMB"
    echo "Disabling Node $NODE_NAME"
    curl -v -b /tmp/cookie -u "$user:$pass" "$JENKINS_URL/computer/$NODE_NAME/toggleOffline"
  
    echo "Waiting for Jobs to Finish"
    ???
  </code></pre>
  
  <p>But after that, I want to wait until any existing jobs that are running are finished before the script exits. I looked through the <code>/api/computer/</code> endpoint and it seems to only list the node names, but does not indicate the number of running jobs. I tried <code>/computer/&lt;worker name&gt;/api/json</code> and <code>xml</code> and they show a bunch of executor attributes, but they don't seem to be populated with metadata on running jobs. They're always empty.</p>
  
  <p>This is running on AWS and I eventually want to call this from SSM Agent (via a Lifecycle hook), triggered whenever an auto-scaling group policy wants to scale down a node. My goal is a clean shutdown, waiting for jobs to finish up so I don't kill a node while a developer has a job running.</p>