"No Stages/Jobs jobs for this pipeline" for branch pipeline
Matthew Martinez
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?
2 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.
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