1

On my gitlab repo I have to trigger pipeline only when a specific folder have changes AND when it's a Merge request (both condition). Especially on .zip file extension, i-e, add a new zip file in this folder, create a Merge request, then run the pipeline.

This is my initial pipeline yaml code:

trigger-ci-zip-file-only:
  stage: prebuild
  extends:
    - .prebuild
    - .preprod-tags
  variables:
    PROJECT_FOLDER: "my-specific-folder"
  before_script:
    - echo "Job currently run in $CI_JOB_STAGE"
    - touch ${CI_PROJECT_DIR}/$PROJECT_FOLDER/prebuild.env
    - cd $PROJECT_FOLDER
  only:
    refs:
      - merge_requests
    changes:
      - ${PROJECT_FOLDER}/*.zip
  artifacts:
    reports:
      dotenv: ${CI_PROJECT_DIR}/${PROJECT_FOLDER}/prebuild.env
  allow_failure: false

As you can see, my pipeline have to be triggered only when there is a change in a specific folder on zip files and only on MR. But in this state, the pipeline is always running when MR is creatd or when I push on an existing MR, even if there is no changes or adding in the specific folder.

I also tried to make some changes on the pipeline yaml code like this:

only:
  refs:
    - merge_requests
      changes:
      - ${PROJECT_FOLDER}/**/*.zip

But the pipeline always running.

Also I tried this:

trigger-ci-zip-file-only:
  stage: prebuild
  extends:
    - .prebuild
    - .preprod-tags
  variables:
    PROJECT_FOLDER: "my-specific-folder"
  before_script:
    - echo "Job currently run in $CI_JOB_STAGE"
    - touch ${CI_PROJECT_DIR}/$PROJECT_FOLDER/prebuild.env
    - cd $PROJECT_FOLDER
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
    - changes:
    - ${PROJECT_FOLDER}/**/*.zip
  when: always
  artifacts:
    reports:
      dotenv: ${CI_PROJECT_DIR}/${PROJECT_FOLDER}/prebuild.env
  allow_failure: false

But the pipeline always running too.

How to make sure the pipeline only run on Merge Request AND only when a .zip file was added to the specific folder ?

french_dev
  • 2,117
  • 10
  • 44
  • 85
  • Are you trying to merge the above pipeline into master? This won't work because a merge-request pipeline is only created for a merge-request and when the zip folder is changed – danielnelz Apr 16 '21 at 09:55
  • @danielnelz, indeed, the purpose of the pipeline is to create a first deployment in a test environment linked to a merge request only which will then be merged in the master branch to deploy in production. When I create a new merge request, the pipeline must start only on adding a new .zip file because the job linked to this pipeline must only take into account this .zip file – french_dev Apr 16 '21 at 12:20
  • Any updates on how you did solve this? – m0e33 Jul 18 '22 at 12:13

0 Answers0