gitgitlabgitlab-cipipelinebranching-strategy

Target and Source branch are not merged in GitLab pipeline


I'm currently experimenting with GitLab. Currently, I'm using the free online version of GitLab and I like it very much. But at the moment, I'm trying to understand the "Merge Request" strategy. Given I've two branches:

  1. master
  2. mydev

Now, assume I've a file called "README1.md" on the master-branch and "README2.md" on the "mydev" branch. Next, I create a merge request from "mydev"-branch to the master-branch and I've the following gitlab-ci.yml file:

image: node:current-alpine

test:
  only:
    - merge_requests
  stage: test
  script:
    - ls -al

So, when upon merge request creation, the pipeline runs and is marked as "detached". But the "ls -al" just shows the README2.md from the "mydev"-branch and not the README1.md from the master-branch. The GitLab documentations stats "With pipelines for merged results, the pipeline runs as if the changes from the source branch have already been merged into the target branch.". So I expected to see both, README1.md (master-branch) and README2.md (mydev-branch) because I assume GitLab is doing the following when running the "merge_requests" pipeline:

  1. Clone repository
  2. Checkout "mydev"-branch
  3. Rebase "mydev"-branch on top of master branch
  4. Run script ("ls -al" command)

But it seems that my assumption is wrong and GitLab just checks out the source branch and just runs the script (GitLab skips step 3). So, can anyone explain what's wrong with my assumption?

What I want to do is, all developers are working on their own branch. When they finished their work, they create a "Merge Request" and the testing-pipeline runs automatically like "the source branch have already been merged into the target branch.".


Solution

  • As far as I understand, you want to use Merged results pipelines feature.

    You should:

    1. Have Gitlab Premium
    2. Enable Merged results pipelines