Skip to content

Commit

Permalink
Trigger child pipeline invoke task buffer flush to track progress (#2…
Browse files Browse the repository at this point in the history
…1471)

Trigger child pipeline invoke task buffer flush to track progress
  • Loading branch information
Pythyu authored Dec 11, 2023
1 parent 8e3aa2f commit c61bbc2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
20 changes: 13 additions & 7 deletions tasks/libs/pipeline_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,19 @@ def wait_for_pipeline(gitlab, pipeline_id, pipeline_finish_timeout_sec=PIPELINE_
+ " by "
+ color_message(commit_author, "bold"),
"blue",
)
),
flush=True,
)
print(
color_message(
"Pipeline Link: "
+ color_message(f"https://gitlab.ddbuild.io/{gitlab.project_name}/pipelines/{pipeline_id}", "green"),
"blue",
)
),
flush=True,
)

print(color_message("Waiting for pipeline to finish. Exiting won't cancel it.", "blue"))
print(color_message("Waiting for pipeline to finish. Exiting won't cancel it.", "blue"), flush=True)

f = functools.partial(pipeline_status, gitlab, pipeline_id)

Expand Down Expand Up @@ -217,7 +219,8 @@ def pipeline_status(gitlab, pipeline_id, job_status):
color_message(
f"Pipeline https://gitlab.ddbuild.io/{gitlab.project_name}/pipelines/{pipeline_id} for {ref} succeeded",
"green",
)
),
flush=True,
)
notify("Pipeline success", f"Pipeline {pipeline_id} for {ref} succeeded.")
return True, job_status
Expand All @@ -227,7 +230,8 @@ def pipeline_status(gitlab, pipeline_id, job_status):
color_message(
f"Pipeline https://gitlab.ddbuild.io/{gitlab.project_name}/pipelines/{pipeline_id} for {ref} failed",
"red",
)
),
flush=True,
)
notify("Pipeline failure", f"Pipeline {pipeline_id} for {ref} failed.")
return True, job_status
Expand All @@ -237,7 +241,8 @@ def pipeline_status(gitlab, pipeline_id, job_status):
color_message(
f"Pipeline https://gitlab.ddbuild.io/{gitlab.project_name}/pipelines/{pipeline_id} for {ref} was canceled",
"grey",
)
),
flush=True,
)
notify("Pipeline canceled", f"Pipeline {pipeline_id} for {ref} was canceled.")
return True, job_status
Expand Down Expand Up @@ -295,7 +300,8 @@ def print_job(name, stage, color, date, duration, status, link):
color_message(
f"[{date}] Job {name} (stage: {stage}) {status} [job duration: {duration // 60:.0f}m{duration % 60:2.0f}s]\n{link}".strip(),
color,
)
),
flush=True,
)

def print_retry(name, date):
Expand Down
11 changes: 7 additions & 4 deletions tasks/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,10 @@ def trigger_child_pipeline(_, git_ref, project_name, variables="", follow=True):
for v in variables.split(','):
data['variables'][v] = os.environ[v]

print(f"Creating child pipeline in repo {project_name}, on git ref {git_ref} with params: {data['variables']}")
print(
f"Creating child pipeline in repo {project_name}, on git ref {git_ref} with params: {data['variables']}",
flush=True,
)

res = gitlab.trigger_pipeline(data)

Expand All @@ -449,10 +452,10 @@ def trigger_child_pipeline(_, git_ref, project_name, variables="", follow=True):

pipeline_id = res['id']
pipeline_url = res['web_url']
print(f"Created a child pipeline with id={pipeline_id}, url={pipeline_url}")
print(f"Created a child pipeline with id={pipeline_id}, url={pipeline_url}", flush=True)

if follow:
print("Waiting for child pipeline to finish...")
print("Waiting for child pipeline to finish...", flush=True)

wait_for_pipeline(gitlab, pipeline_id)

Expand All @@ -463,7 +466,7 @@ def trigger_child_pipeline(_, git_ref, project_name, variables="", follow=True):
if pipestatus != "success":
raise Exit(f"Error: child pipeline status {pipestatus.title()}", code=1)

print("Child pipeline finished successfully")
print("Child pipeline finished successfully", flush=True)


def parse(commit_str):
Expand Down

0 comments on commit c61bbc2

Please sign in to comment.