Created
May 22, 2020 13:40
-
-
Save andyreagan/ce25939367bcb2e6be9ce4f41a5edd8f to your computer and use it in GitHub Desktop.
Shell script to wait on a upstream jenkins job - a "block" node in an execution graph
This file contains 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
# watch multiple jobs, can handle any number of upstreams | |
virtualenv-3.5 pyenv | |
pyenv/bin/pip install requests | |
JENKINS_URI=... | |
echo "import json | |
import requests | |
import time | |
jobs = '${JOB_TO_WAIT_FOR}'.strip().split(',') | |
anime = [True for job in jobs] | |
while sum(anime) > 0: | |
for i, job in enumerate(jobs): | |
if anime[i]: | |
r = requests.get('{JENKINS_URI}/job/{job}/api/json?pretty=true'.format(job=job)) | |
print(r.content) | |
x = json.loads(r.content.decode('utf-8')) | |
print(x) | |
anime[i] = ('anime' in x['color']) | |
time.sleep(5) | |
time.sleep(5) | |
for job in jobs: | |
r = requests.get('{JENKINS_URI}/job/{job}/api/json?pretty=true'.format(job=job)) | |
print(r.content) | |
x = json.loads(r.content.decode('utf-8')) | |
print('-'*80) | |
print(x) | |
# make sure it was a success | |
assert x['lastCompletedBuild']['number'] == x['lastSuccessfulBuild']['number'] | |
" | pyenv/bin/python - | |
# watch single job, so it can handle two upstreams | |
virtualenv-3.5 pyenv | |
pyenv/bin/pip install requests | |
echo "import json | |
import requests | |
import time | |
anime = True | |
while anime: | |
r = requests.get('{JENKINS_URI}/job/${JOB_TO_WAIT_FOR}/api/json?pretty=true') | |
print(r.content) | |
x = json.loads(r.content.decode('utf-8')) | |
print(x) | |
anime = ('anime' in x['color']) | |
time.sleep(5) | |
time.sleep(5) | |
r = requests.get('{JENKINS_URI}/job/${JOB_TO_WAIT_FOR}/api/json?pretty=true') | |
print(r.content) | |
x = json.loads(r.content.decode('utf-8')) | |
print('-'*80) | |
print(x) | |
# make sure it was a success | |
assert x['lastCompletedBuild']['number'] == x['lastSuccessfulBuild']['number'] | |
" | pyenv/bin/python - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment