Prevent running CI/CD without semi-linear history

:hugs: Please help fill in this template with all the details to help others help you more efficiently. Use formatting blocks for code, config, logs and ensure to remove sensitive data.

Problem to solve

When we don’t have a semi-linear history, their might be changes in the target branch that are not on the source branch.

I want the CI result to show me what I will have after the merge
But since the CI runs on the source branch, it does not know the things that changed on the target. Therefore, to achieve my goal, I only want to run the CI if I have a linear history.

NOTE: I can already prevent the merge (Merge methods | GitLab). What I want is preventing the CI from running.

Steps to reproduce

  1. Take a branch master with a file containing:

The CI must simply echo the content of the file.

  1. Create 2 branches (dev1 and dev2)
  2. In branch dev1, remove “foo” and merge in master
  3. In branch dev2, remove “bar” and prepare the merge request

The CI will show


When I want to see


This is because of the history linearity, and I must be able to block the CI from running in this scenario.

As far as I understand the only way to do it is to have specific job which will run and check changes using git merge from main branch and emit a variable like: skip_the_rest_of_ci=true. And the next jobs have to have

    - if: '$skip_the_rest_of_ci != "true"'

or have it in the task itself:

- |
  [ skip_the_rest_of_ci = "true" ] && exit 0