@@ -94,24 +94,32 @@ def fetch_buildkite_data(build_url):
9494
9595
9696def download_log (job_url , output_path ):
97- # Construct raw log URL: job_url + "/raw" (Buildkite convention)
98- # job_url e.g. https://buildkite.com/org/pipeline/builds/14394#job-id
99- # Wait, the job['path'] gives /org/pipeline/builds/14394#job-id
100- # We want /org/pipeline/builds/14394/jobs/job-id/raw? No
101- # The clean URL for a job is https://buildkite.com/org/pipeline/builds/14394/jobs/job-id
102- # And raw log is https://buildkite.com/org/pipeline/builds/14394/jobs/job-id/raw
103-
104- # We have full_url e.g. https://buildkite.com/bazel/rules-python-python/builds/14394#019c5cf9-e3cf-468f-a7b1-8f9f5ad4b08c
105- # We need to transform it.
97+ # job_url looks like:
98+ # https://buildkite.com/bazel/rules-python-python/builds/15594#019e879b-...
99+ # We need to transform it to:
100+ # https://buildkite.com/organizations/bazel/pipelines/rules-python-python/builds/15594/jobs/{job_id}/download.txt
106101
107102 if "#" in job_url :
108103 base , job_id = job_url .split ("#" )
109- # Ensure base doesn't end with /
110- if base .endswith ("/" ):
111- base = base [:- 1 ]
112-
113- # Build raw URL
114- raw_url = f"{ base } /jobs/{ job_id } /raw"
104+ base = base .rstrip ("/" )
105+
106+ # Parse the path segments: https://buildkite.com/org/pipeline/builds/N
107+ # Rebuild with the /organizations/org/pipelines/pipeline/ format which
108+ # supports the /jobs/{id}/download.txt log URL without auth.
109+ parts = base .split ("/" )
110+ # parts = ["https:", "", "buildkite.com", "org", "pipeline", "builds", "N"]
111+ if len (parts ) >= 7 and parts [2 ] == "buildkite.com" :
112+ org = parts [3 ]
113+ pipeline = parts [4 ]
114+ build_num = parts [6 ] if len (parts ) >= 7 else ""
115+ raw_url = (
116+ f"https://buildkite.com/organizations/{ org } "
117+ f"/pipelines/{ pipeline } "
118+ f"/builds/{ build_num } "
119+ f"/jobs/{ job_id } /download.txt"
120+ )
121+ else :
122+ raw_url = f"{ base } /jobs/{ job_id } /download.txt"
115123 else :
116124 print (f"Could not parse job URL for download: { job_url } " , file = sys .stderr )
117125 return False
0 commit comments