<p>I'd go with what gitlab already offers, the <a href="https://docs.gitlab.com/ee/ci/yaml/#onlyexcept-advanced" rel="nofollow noreferrer">only/except</a> keyword.</p>

<p>Something like:</p>

<pre><code>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-.*/
</code></pre>

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

<p>the <code>refs</code> keyword accept regexes to match, more details on <a href="https://docs.gitlab.com/ee/ci/yaml/#onlyexcept-basic" rel="nofollow noreferrer">gitlab-ci docs here</a></p>

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

<pre><code>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
</code></pre>

<p>Or with a single regex:</p>

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

<p>I didn't test those entries above, let me know if one fail</p>

CC BY-SA 4.0
2020-03-06T19:03:57.210Z
Flagging as no longer needed/too chatty :) You know you can superping me in chatops, right?
Tensibai
CC BY-SA 4.0
2020-02-20T13:40:14.460Z
2020-02-20T13:40:14.460Z
Tensibai
<p>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.</p>

<p>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.</p>

<p>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.</p>

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

<p>Thank you :)</p>

<gitlab>
per-merge request GitLab CI pipeline customization
vonovak
# per-merge request GitLab CI pipeline customization

(Asked by: username_0 on 2020-02-20)

We have a gitlab CI pipeline for building&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 :)

**Tags:** gitlab


---

## 1 answers

### Answer by username_1 on 2020-02-20. Score: 1

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

> **Comments:**
> **username_1**: Flagging as no longer needed/too chatty :) You know you can superping me in chatops, right?  

---

