Respect stage order when using rules changes (to monitor specific files)

consider the following gitlab-ci.yaml, for a mono repo with multiple microfrontends

stages:
 - build
 - deploy

build:app1:
  stage: build
  script: 
    - sleep 30
    - mkdir dist1
    - touch dist1/output1.html
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
    changes:
       - app1/src/*
  artifacts:
    paths:
      - dist1
 

build:app2:
  stage: build
  script: 
    - sleep 30
    - mkdir dist2
    - touch dist2/output2.html
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
    changes:
       - app2/src/*
  artifacts:
    paths:
      - dist2

deploy:all:
   stage: deploy
   script:
      - mkdir dist
      - cp dist1/* dist
      - cp dist2/* dist
      - deploy.sh ./dist
   artifacts:
     paths:
       - dist

when ran the order defined in stages is ignored and both the build and deploy jobs run simultaneously
causing a failure for the “deploy:all” job (since its still “building”)

if i remove the condition for the changes the stage order is respected and build runs before deploy

how can i both only act on changes and enforce the defined build order?

in the real monorepo there are 10’s of micro frontends not just 2 …

1 Like

I have now tried also adding needs to the build:all job and that was also unsuccessfull

deploy:all:
   stage: deploy
   needs:
          - job: build:app1
            optional: true
          - job: build:app2
            optional: true

the deploy job still runs concurrently with the build jobs

I have also posted a bounty in stackoverflow for this question

This problem is resolved … see the linked stackoverflow for the solution that ended up working

It was really some combination of all 3 answers provided but i think the accepted one (that it wasnt part of the same pipeline) was correct