Skip to content

Instantly share code, notes, and snippets.

@sfc-gh-eraigosa
Created February 2, 2018 19:55
Show Gist options
  • Save sfc-gh-eraigosa/ecb6bc68637384a987a26b0d2037c6d6 to your computer and use it in GitHub Desktop.
Save sfc-gh-eraigosa/ecb6bc68637384a987a26b0d2037c6d6 to your computer and use it in GitHub Desktop.

Use this script to look for a running jenkins job on slave worker

function waitforjob() {
  jekins_slave_pid=$(ps -ef|grep slave.jar | awk '{print $2"="$8}'|grep java|awk -F'=' '{print $1}')
  if [  ! -z "${jekins_slave_pid}" ] ; then
    while pstree -pnlac ${jekins_slave_pid} |grep hudson > /dev/null 2<&1; do
       echo 'waiting for job to finish'; 
       sleep 5;
    done
  else
    echo 'slave agent is down'
  fi
  echo 'jenkins is not running a job'
}

waitforjob

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment