20 set TclPath [
file dirname [
info script]]/..
21 set repo_path [
file normalize "$TclPath/../.."]
22 source $TclPath/hog.tcl
24 set usage "- CI script that downloads artifacts from child pipelines.\n USAGE: $::argv0 <project id> <commit SHA> <create_job id>."
26 if { [
llength $argv] < 3 } {
32 set proj_id [
lindex $argv 0]
33 set commit_sha [
lindex $argv 1]
34 set create_job_id [
lindex $argv 2]
37 lassign [
ExecuteRet glab api "/projects/$proj_id/jobs/?page=1"] ret msg
39 Msg Error "Some problem when getting parent pipeline: $msg"
42 set result [
catch {
package require json} JsonFound]
43 if {"$result" != "0"} {
44 Msg Error "Cannot find JSON package equal or higher than 1.0.\n $JsonFound\n Exiting"
48 set ChildList [json::json2dict $msg]
49 foreach Child $ChildList {
50 set result [
catch {dict get $Child "id"} child_job_id]
51 if {"$result" != "0" || $child_job_id < $create_job_id} {
54 set result [
catch {dict get [dict get $Child "commit"] "id"} child_sha]
55 if {"$result" != "0"} {
56 Msg Error "Error when retrieving SHA of child process $child_job_id. Error message:\n $child_sha\n Exiting"
59 if { "$child_sha" != "$commit_sha" } {
64 set result [
catch {dict get $Child "name"} job_name]
65 if {"$result" != "0" || "$job_name" != "collect_artifacts"} {
70 set result [
catch {dict get $Child "artifacts"} artifact_list]
71 if {"$result" != "0"} {
75 foreach artifact $artifact_list {
76 set result [
catch {dict get $artifact "file_type"} file_type]
77 if {"$result" != "0"} {
78 Msg CriticalWarning "Problem when reading artifact for child process $job_name"
81 if {"$file_type" == "archive"} {
85 if {$withArchive == "0"} {
86 Msg Info "No archive artifacts found for child job $job_name, ignoring it\n"
90 Msg Info "Downloading artifacts for child job at: projects/${proj_id}/jobs/${child_job_id}/artifacts/"
91 lassign [
ExecuteRet glab api "/projects/${proj_id}/jobs/${child_job_id}/artifacts/" > output_${child_job_id}.zip] ret msg
93 Msg Error "Some problem when downloading artifacts for child job id:$child_job_id. Error message: $msg"
96 Execute unzip -o output_${child_job_id}.zip
97 file delete output_${child_job_id}.zip