Skip to content

Use merge request HEAD ref for detached merge request pipelines

Shinya Maeda requested to merge persist-fulll-ref-path-for-mr-pipelines into master

What does this MR do?

Currently, Pipelines for merge requests use branch ref (e.g. refs/heads/feature) to create a pipeline. This pipeline works nicely and it's displayed on merge requests, however, we should use merge request HEAD refs (e.g. refs/merge-requests/:iid/head) in order to tightly couple the git reference with a corresponding merge request.

Basically, the expected results from job execution perspective is exactly the same with using branch pipelines, because merge request head refs point to the same SHA with branch ref.

This is a breaking change, but very important step for our final goal Use combined merge refs with merge request pipelines. We'll eventually have to use merge request merge ref (e.g. refs/merge-requests/:iid/merge). We should implement the fundamental components at this step in order for reducing the change size of the final MR.

The safe mechanism

By using merge request refs (regardless of head or merge), we'll lose backward compatibility because there are two requirements for running pipelines successfully:

  1. GitLab-Runner 11.9 (i.e. refspecs feature)
  2. Target project and source project of the merge request are the same. (i.e. not forked project)

If 1. is missing, detached merge request pipelines fail because it cannot checkout source code properly. In order to switch back to the old behavior, we add a feature flag (ci_use_merge_request_ref). We can easily fall back to the old behavior by running Feature.disable(:ci_use_merge_request_ref).

If a user submitted a merge request from a forked project, then it automatically uses legacy detached merge request pipelines. This is the current behavior that runs a job on branch ref.

Manual QA - Thu Mar 21 10:48:25 UTC 2019

Context: When runner is new

Expected:

  • The job fetches HEAD merge request ref (refs/merge-requests/:iid/head) and succeeds
  • Correctly renders detached merge request pipeline identifer in merge request widget
  • Correctly renders detached merge request pipeline identifer in pipeline list page
  • Correctly renders detached merge request pipeline identifer in pipeline details page
  • Correctly renders detached merge request pipeline identifer in job details page

Context: When source project is a forked project

Expected:

  • The job fetches HEAD branch ref (refs/heads/branch-name) and succeeds

Context: When runner is old

Expected:

  • The job fails with the reason that they're using an old runner

Context: When ci_use_merge_request_ref feature flag is disabled

Expected:

  • The job fetches HEAD branch ref (refs/heads/branch-name) and succeeds

Context: When source project is a forked project

Expected:

  • The job fetches HEAD branch ref (refs/heads/branch-name) and succeeds

What are the relevant issue numbers?

Related: https://gitlab.com/gitlab-org/gitlab-ee/issues/7380

Close: https://gitlab.com/gitlab-org/gitlab-ce/issues/58454

Does this MR meet the acceptance criteria?

Edited by Kamil Trzciński

Merge request reports