Gitlab CI Run jobs conditionally with rules:changes

  • Only run a job if there are changes in a certain folder
  • It compares changes by comparing the current to the default branch
  • The file path in rules:changes must not start with ./
  • Any jobs that depend on a previous job with needs also need that rule for it to work
variables:
  DIR_BACKEND: backend
 
.rules-backend: &rules-backend
  - if: *on-mr
    when: always
    changes:
      - ${DIR_BACKEND}/*
 
docker-build-backend:
  extends: .docker
  needs:
    - job: build-backend
  rules:
    - *rules-backend
  script: echo "building"