Created
July 30, 2015 15:51
-
-
Save simon-weber/35f5d27a21ebf9b8ad8e to your computer and use it in GitHub Desktop.
recursively get all downstream jenkins artifact urls
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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
subBuilds
key might be specific to the multijob plugin; I haven't tested this without it.