From c16ae4ea464e3af84baaaea65c406cba55643b4d Mon Sep 17 00:00:00 2001 From: Tim Jaacks <tim.jaacks@garz-fricke.com> Date: Mon, 13 Dec 2021 21:22:25 +0100 Subject: [PATCH] check_pipeline_status: add parameter for trigger source --- check_pipeline_status.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/check_pipeline_status.py b/check_pipeline_status.py index 71eb0cd7..8c0ebe98 100755 --- a/check_pipeline_status.py +++ b/check_pipeline_status.py @@ -9,11 +9,13 @@ from gitlab import Gitlab, GitlabGetError from gitlab.v4.objects import Project -def check_pipeline_status(project: Project, commit): +def check_pipeline_status(project: Project, commit, source): """Get latest pipeline status for a given commit""" # Find pipeline for commit - pipelines = project.pipelines.list(sha=commit, retry_transient_errors=True) + pipelines = project.pipelines.list( + sha=commit, source=source, retry_transient_errors=True + ) if not pipelines: print("ERROR: no pipeline for commit '%s' found" % commit) sys.exit(1) @@ -58,13 +60,21 @@ def main(): dest="commit", required=True, ) + parser.add_argument( + "--source", + help="""source that triggered the pipeline""", + choices=["push", "merge_request_event"], + dest="source", + default="push", + required=False, + ) args, _ = parser.parse_known_args() gitlab = Gitlab(args.gitlab_url, private_token=args.token) project = common.get_project(gitlab, args.project) - status = check_pipeline_status(project, args.commit) + status = check_pipeline_status(project, args.commit, args.source) # If we are running in a job environment and the upstream status is canceled, # explicitly cancel this job as well -- GitLab