gitcontinuous-integrationgitlab

GitLab CI/CD: Run jobs only when files in a specific directory have changed


I would like to run specific jobs on the .gitlab-ci.yaml if and only if files within specific directories of the repository have changed. Is there a way to do this with gilab's ci/cd tooling or would it be easier just to run a custom build script?


Solution

  • Changes policy introduced in GitLab 11.4.

    For example:

    docker build:
      script: docker build -t my-image:$CI_COMMIT_REF_SLUG .
      only:
        changes:
          - Dockerfile
          - docker/scripts/*
          - dockerfiles/**/*
          - more_scripts/*.{rb,py,sh}
    

    In the scenario above, if you are pushing multiple commits to GitLab to an existing branch, GitLab creates and triggers the docker build job, provided that one of the commits contains changes to either:

    You can read more in the documentation and with some more examples.