Forked from matthewlmcclure/kill-processes-orphaned-by-jenkins.sh
Created
April 2, 2014 19:26
-
-
Save jeffbeard/9941298 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/bash | |
| # Tested on Mac OS X (BSD). Probably needs `ps` arguments ported for Linux (GNU). | |
| for url in $(ps -wwEf | grep BUILD_URL | grep -v ' grep' | tr ' ' '\n' | grep BUILD_URL | sort | uniq | awk -F'=' '{ print $2 }') | |
| do | |
| # Get your API token from | |
| # http://<jenkins-host>/user/<user>/configure > Show API | |
| # Token... | |
| curl -s -u '<user>:<token>' "$url"'/api/json?tree=building' | grep -q true | |
| building=$? | |
| false=1 | |
| if [ $building -eq $false ] | |
| then | |
| for pid in $(ps -wwEf | grep "$url" | grep -v ' grep' | awk '{ print $2 }') | |
| do | |
| echo 'Finished job: '"$url" | |
| echo 'Killing process orphaned by Jenkins:' | |
| ps -f -p $pid | |
| echo | |
| kill -9 $pid | |
| done | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment