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