"No Stages/Jobs jobs for this pipeline" for branch pipeline
Asked Answered
S

2

8

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?

Swan answered 7/6, 2021 at 12:58 Comment(0)
S
6

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.

Swan answered 7/6, 2021 at 12:58 Comment(2)
no jobs other than the ones in .pre are added on merge request events, what about test and build ? Why are they not considered as individual stages independent of .pre ?Kiln
My pipeline was executed on a merge request - so CI_COMMIT_BRANCH was not the default branch (as the related jobs' rules require); hence they were not added to the pipeline. This resulted in no other jobs being added aside from the ones in .pre and .post stages.Swan
D
2

I'm glad you added this info into the question: However, no jobs are run for merge requests

CI_COMMIT_BRANCH is not available in MR-based events. Here is an fragment from official docs:

The commit branch name. Available in branch pipelines, including pipelines for the default branch.
**Not available in merge request pipelines or tag pipelines.**

When working with MR and willing to check against branch name, you might want to use: CI_MERGE_REQUEST_SOURCE_BRANCH_NAME or CI_MERGE_REQUEST_TARGET_BRANCH_NAME

List of envs here

Duroc answered 19/12, 2022 at 12:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.