From 095da4c521e37f953630bf7721790c9fe3cc5d47 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Sat, 16 Jul 2022 11:02:51 +0530 Subject: [PATCH] ci: Fix project URL when triggering cerbero pipelines When merge request pipelines are triggered on the gstreamer namespace, CI_PROJECT_URL will be gitlab.[...]/gstreamer/gstreamer but we need to use gitlab.[...]/$USER/gstreamer because that's where the source branch is located. This exhibits as cerbero pipelines failing because it can't find the specified branch: https://gitlab.freedesktop.org/gstreamer/cerbero/-/pipelines/639379 Part-of: --- ci/gitlab/trigger_cerbero_pipeline.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ci/gitlab/trigger_cerbero_pipeline.py b/ci/gitlab/trigger_cerbero_pipeline.py index b349146148..977296368c 100755 --- a/ci/gitlab/trigger_cerbero_pipeline.py +++ b/ci/gitlab/trigger_cerbero_pipeline.py @@ -8,7 +8,6 @@ import gitlab CERBERO_PROJECT = 'gstreamer/cerbero' - class Status: FAILED = 'failed' MANUAL = 'manual' @@ -40,12 +39,24 @@ if __name__ == "__main__": job_token=os.environ.get('CI_JOB_TOKEN')) cerbero = gl.projects.get(CERBERO_PROJECT) + + # CI_PROJECT_URL is not necessarily the project where the branch we need to + # build resides, for instance merge request pipelines can be run on + # 'gstreamer' namespace. Fetch the branch name in the same way, just in + # case it breaks in the future. + if 'CI_MERGE_REQUEST_SOURCE_PROJECT_URL' in os.environ: + project_url = os.environ['CI_MERGE_REQUEST_SOURCE_PROJECT_URL'] + project_branch = os.environ['CI_MERGE_REQUEST_SOURCE_BRANCH_NAME'] + else: + project_url = os.environ['CI_PROJECT_URL'] + project_branch = os.environ['CI_COMMIT_REF_NAME'] + pipe = cerbero.trigger_pipeline( token=os.environ['CI_JOB_TOKEN'], ref=os.environ["GST_UPSTREAM_BRANCH"], variables={ - "CI_GSTREAMER_URL": os.environ["CI_PROJECT_URL"], - "CI_GSTREAMER_REF_NAME": os.environ["CI_COMMIT_REF_NAME"], + "CI_GSTREAMER_URL": project_url, + "CI_GSTREAMER_REF_NAME": project_branch, # This tells cerbero CI that this is a pipeline started via the # trigger API, which means it can use a deps cache instead of # building from scratch.