"No Stages/Jobs jobs for this pipeline" for branch pipeline

Viewed 10462

Given the following .gitlab-ci.yml:

---
stages:
  - .pre
  - test
  - build

compile-build-pipeline:
  stage: .pre
  script: [...]
  artifacts:
    paths: [".artifacts/build.yaml"]

lint-source:
  stage: .pre
  script: [...]

run-tests:
  stage: test
  rules:
    - if: '$CI_COMMIT_BRANCH == "$CI_DEFAULT_BRANCH"'
  trigger:
    strategy: depend
    include:
      artifact: .artifacts/tests.yaml
      job: "compile-test-pipeline"
  needs: ["compile-test-pipeline"]

build-things:
  stage: test
  rules:
    - if: '$CI_COMMIT_BRANCH == "$CI_DEFAULT_BRANCH"'
  trigger:
    strategy: depend
    include:
      artifact: .artifacts/build.yaml
      job: "compile-build-pipeline"
  needs: ["compile-build-pipeline"]
...

The configuration should always run (any branch, any source). Tests and build jobs should be run only on the default branch.

However, no jobs are run for merge requests, and manually triggering the pipeline on branches other than the default one give the error No Jobs/Stages for this Pipeline.

I've tried explicitly setting an always run rule using rules: [{if: '$CI_PIPELINE_SOURCE'}] to the jobs in the .pre stage, but no dice.

What am I doing wrong?

1 Answers

As per the docs:

You must have a job in at least one stage other than .pre or .post.

In the above configuration, no jobs other than the ones in .pre are added on merge request events, hence no jobs are added at all.

Related