'Running pipeline returns No stages / jobs for this pipeline

I'm trying to run gitlab CI stages based on which files changed in the MR. The changes: rule is not sufficient because for example: A MR contains changes in two different directories X & Y and two stages that are run based on changes in X or Y. If you run the pipeline in the MR first time and job X runs and fails the merge can't happen, but if you run it a second time with changes to Y then the pipeline runs only stage Y and it succeeds. Even though the first pipeline which had errors in directory X failed. My attempt on this is:

image: docker:latest

services:
  - docker:dind

renovate:
  stage: build
  variables:
    DIR_IN_MR: $(git diff --name-status $CI_MERGE_REQUEST_TARGET_BRANCH_NAME..$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME | cut -f2 | cut -d '/' -f 1 | uniq | grep -q dir_x && echo $?)
  rules:
    - if: $DIR_IN_MR == "0"
  script:
    - echo 1

My problem is when I try to run it, it returns No stages / jobs for this pipeline even though dir_x exists in the project. How can this be solved?



Solution 1:[1]

Defining stages is missing in your .gitlab-ci.yml You have to define stages (as renovate job use build stage) :

stages: 
  - build

also you rule is not correct. If you want to execute job only on MR and if changes are done in dir_x, you have to define rule like :

rules:
  - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
    changes:
      - dir_x/**/*

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nicolas Pepinster