Fix UBI image trigger artifact ref for merge train and detached pipelines

The downstream gitlab-runner-ubi-images pipeline often failed with "This job could not start because it could not retrieve the needed artifacts." (internally missing_dependency_failure).

Its build and push ubi images from parent pipeline job fetches the binaries artifacts from gitlab-runner by ref:

  needs:
    - ref: $UPSTREAM_CI_COMMIT_REF
      project: gitlab-org/gitlab-runner
      job: binaries
      artifacts: true

.trigger-downstream-pipeline-ref unconditionally set UPSTREAM_CI_COMMIT_REF to refs/merge-requests/<iid>/merge for all merge request pipelines. That ref only exists for merged-results pipelines. When the MR ran as a merge train (ref .../train) or a detached pipeline (ref .../head), no pipeline existed at .../merge, so the cross-project artifact lookup resolved to nothing and the downstream job failed before starting -- even though the binaries artifacts existed under the actual pipeline ref.

This explains the intermittent nature: triggers from merged-results pipelines succeeded, while triggers from merge-train or detached pipelines failed. Confirmed against the pipelines for MRs 6830 (merge train) and 6874 (detached), both of which failed, versus 6870 and 6858 (merged results), which succeeded.

Set UPSTREAM_CI_COMMIT_REF based on CI_MERGE_REQUEST_EVENT_TYPE so it points at the ref where the binaries actually live (.../train, .../head, or .../merge). Branch (default-branch) and tag triggers are unaffected: they match on CI_COMMIT_BRANCH/CI_COMMIT_REF_NAME, which are mutually exclusive with the merge_request_event rules.

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

Merge request reports

Loading