1

I want to run step in pipeline only when something has changed in specific direction. I tried with except, only changes and rules and none of this has worked. Is it even possible to do that condition and if yes, how do I do it?

This is my config

test-backend:
  stage: test
  image: maven:latest
  script:
    - cd backend
    - mvn $MAVEN_CLI_OPTS test
  rules:
    - changes:
      - backend/**

and I have same config for frontend and I want to run test only when something has changed in backend and same for frontend.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Mateusz Sobczak
  • 1,551
  • 8
  • 33
  • 67
  • 1
    https://stackoverflow.com/questions/51661076/gitlab-ci-cd-run-jobs-only-when-files-in-a-specific-directory-have-changed – b2f Oct 05 '21 at 16:43
  • Does this answer your question? [GitLab CI/CD: Run jobs only when files in a specific directory have changed](https://stackoverflow.com/questions/51661076/gitlab-ci-cd-run-jobs-only-when-files-in-a-specific-directory-have-changed) – Adam Marshall Oct 05 '21 at 17:41
  • @AdamMarshall sorry but your link didn't help me – Mateusz Sobczak Oct 06 '21 at 09:13
  • Can you explain why it didn’t help or how your scenario is different than the other question? – Adam Marshall Oct 06 '21 at 13:12
  • 1
    Note that you have defined two rules. Simply remove the `- when: always` line (or at least the hyphen before the `when:`). – slauth Oct 06 '21 at 14:25
  • @slauth when I deleted when: always I have still the same problem. Task doesn't run – Mateusz Sobczak Oct 09 '21 at 13:22

1 Answers1

0

I tried to reproduce this, and i actually could. It seems like an issue with the evaluation of the pipeline. As soon as i added a build which just echoed something, and ran without the changes the changes worked. But if there was no job, it was not picked up.

Therefore i suggest to add a job like the following one, to simply ensure the pipeline runs all the time. (i know this might be suboptimal as it costs build minutes but it is a workaround which might help)

start:
  stage: .pre
  script: echo something

Important to note

If you plan to use this for your merge requests, be aware that you activate Merged Results for Pipelines - else each commit is treated on its own for those changes, and your merge request might be passing builds, as the changes have been done in a previous commit and are not part of the most recent one!!

Simon Schrottner
  • 4,146
  • 1
  • 24
  • 36