Merge requests


Merge requests

Merge requests enable collaboration

Pipelines can automatically test merge requests

Commits to a branch with a merge request cause multiple events:

  1. Push event to branch -> branch pipeline
  2. Merge request event -> merge request pipeline

Use rules to decide which jobs to run when

GitLab offers $CI_PIPELINE_SOURCE with event name


Merge request pipelines

What make them different

Only run when configured using the rules keyword

Have access to more pre-defined variables

Do not have access to protected variables


Hands-On

See chapter Merge requests


Pro tip 1: Rule templates

Pipelines often have many jobs

Rules will be repeated multiple times

Combine rules with templates to prevent repetition

.rule-only-web:
  rules:
  - if: $CI_PIPELINE_SOURCE == 'web'

job_name:
  extends:
  - .rule-only-web
  #...

Pro tip 2: Integration with SonarQube

Merge request decoration

Write scan results into merge request

Requires Developer Edition

Quality Gates

Wait for quality gates:

sonar-scanner -Dsonar.qualitygate.wait=true

Pro tip 3: Pipelines and multiple branches

Pipeline is executed from .gitlab-ci.yml in the branch

Test changes to pipeline in a branch


Pro tip 4: Merged results pipelines

Runs after a merge

Only available in Premium subscription