per-merge request GitLab CI pipeline customization We have a gitlab CI pipeline for building&amp;testing our product. Our product can be, fairly clearly, divided into two distinct parts - let's say we call them A and B. The most time-consuming part of our pipeline are end-to-end (e2e) tests that take > 40 minutes to execute, and we want to cut this time down. They are currently executed in 1 job.

Because our product consists of A and B, for each merge request we want to run only a subset of our e2e tests (only tests for A or only tests for B or all) - we want to be able to specify this manually for each merge request.

We were looking for some idiomatic way to do this in GitLab CI, but didn't find one. What is the cleanest, least obtrusive way to achieve this? We ofc also want to be able to run all e2e tests - this would be the case of master branch.

Our ideas included encoding this information in commit messages or merge request title and extracting this from env variables - https://docs.gitlab.com/ee/ci/variables/predefined_variables.html but both seem like a hack.

Thank you :)
I'd go with what gitlab already offers, the only/except keyword.

Something like:

test:e2e:A:
  script:
    - whatever you do to test A part
  only:
   refs:
      - master
      - /^A-.*/

test:e2e:B:
  script:
    - whatever you do to test B part
  only:
   refs:
      - master
      - /^B-.*/


The only requirement is that work on A or B is done in branches prefixed with A- or B-.

the refs keyword accept regexes to match, more details on gitlab-ci docs here

If your gitlab is pretty recent (>12.3) the rules method would be prefered and the example above for A would become:

test:e2e:A:
  script:
    - whatever you do to test A part
  rules:
    - if: $CI_COMMIT_REF_NAME =~ /^A-.*$/
    when: always
    - if: $CI_COMMIT_REF_NAME =~ /^master$/
    when: always


Or with a single regex:

test:e2e:A:
  script:
    - whatever you do to test A part
  rules:
    - if: $CI_COMMIT_REF_NAME =~ /^(A-.*|master)$/ 
    when: always


I didn't test those entries above, let me know if one fail