How to list the modified files?

Gajus picture Gajus · Oct 20, 2018 · Viewed 7.2k times · Source

I am using to run scripts defined in .gitlab-ci.yml whenever a PR is raised.

I want to get the list of modified files since the last commit.

The use case is to run file-specific integration tests in a large codebases.

Answer

Gajus picture Gajus · Oct 20, 2018

If you do not need to know the paths, but you simply need to run a specific job only when a specific file is changed, then use only/changes .gitlab-ci.yml configuration, e.g.

docker build:
  script: docker build -t my-image:$CI_COMMIT_REF_SLUG .
  only:
    changes:
      - Dockerfile
      - docker/scripts/*

Alternatively, if you need to get paths of the modified scripts, you can use CI_COMMIT_BEFORE_SHA and CI_COMMIT_SHA environment variables, e.g.

> git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA
src/countries/gb/homemcr.js
src/countries/gb/kinodigital.js