Skip to content

Instantly share code, notes, and snippets.

@simon-weber
Created July 30, 2015 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save simon-weber/35f5d27a21ebf9b8ad8e to your computer and use it in GitHub Desktop.
Save simon-weber/35f5d27a21ebf9b8ad8e to your computer and use it in GitHub Desktop.
recursively get all downstream jenkins artifact urls
#!/usr/bin/env python
"""
Run on Jenkins to print a url for each artifact generated by a downstream multijob build.
"""
import os
import requests
JENKINS_URL = os.environ['JENKINS_URL']
BUILD_URL = os.environ['BUILD_URL']
def find_artifact_urls(build_url):
artifact_urls = []
res = requests.get('%s/api/json' % build_url, verify=False).json()
if 'subBuilds' in res:
for subbuild in res['subBuilds']:
artifact_urls.extend(find_artifact_urls(JENKINS_URL + subbuild['url']))
if 'artifacts' in res:
for artifact in res['artifacts']:
artifact_urls.append("%sartifact/%s" % (res['url'], artifact['relativePath']))
return artifact_urls
for url in find_artifact_urls(BUILD_URL):
print url
@simon-weber
Copy link
Author

  • note that the subBuilds key might be specific to the multijob plugin; I haven't tested this without it.
  • we use this at Venmo to implement a fork/join style workflow -- the top-most build creates many parallel children, waits for them to finish, then collects their results (tests, coverage, etc) and merges them

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