1

I have task to create simple GitLab CI file to run a job only if two files have been changed. In official GitLab docs I have not found nothing about this. I need to run a job only if file A changed and also file B changed.

2 Answers2

0

In this case, you don't have to change by yourself, every time if you change/commit your File A and File B, GitLab CI will allow your files to automatically run as a job

Ya Min Oo
  • 55
  • 7
0

Option A - Only/Except https://docs.gitlab.com/ee/ci/yaml/#onlyexcept-advanced

This is the correct way to do it

your-step:
  script:
    - your-script.sh
  only:
    changes:
      - "file*.extension" # I don't know the pattern of your files

Option B - Using shell script

You can do anything with shell script (or any other language)

in this link https://gitlab.com/gitlab-org/gitlab-foss/-/issues/19813 you will see a lot of options to do it. Just try if something fits to your purpose

Option C - Using gitlab rules https://docs.gitlab.com/ee/ci/yaml/#rules

In the example below, the job will be triggered if any of the conditions match

your-step:
  script:
    - your-script.sh
  rules:
    - changes: 
      - fileA
      - file B
      - dir-with-both-files/*

Sergio Tanaka
  • 1,325
  • 1
  • 6
  • 18
  • 1
    Thank you for your answer. The thing is that I am using currently the solution you provided. And it is not working well for me. Because, we have to run a job only if two files changes, not either one of files but, file A and B. Job should not be executed in any other way. Is it possible to do that? – Raysultan Karimov Jun 11 '20 at 03:22