Lets suppose Pipeline A is a multi-project pipeline. and Pipeline B is Parent-child Pipeline.
Pipeline B is triggering jobs based on the changes inside each of its subfolders.
Structure of Project B:
.gitlab-ci.yml (here, referred as Pipeline B)
subfolder1/.gitlab-ci.yml
subfolder2/.gitlab-ci.yml
stages:
- setup
subfolder1-job:
stage: setup
trigger:
include: subfolder1/.gitlab-ci.yml
strategy: depend
rules:
- if: $CI_COMMIT_BRANCH != "main" # when the commit happens in any other branches other than main
changes:
compare_to: 'refs/heads/main'
paths:
- subfolder1/*
- if: '$CI_COMMIT_TAG || $CI_MERGE_REQUEST' #it should not run in any MR/TAG
when: never
- if: $CI_PIPELINE_SOURCE == "pipeline" # **this is the block which needs to be developed.**
This code works perfectly fine when there is a change in the subfolders and on any branches other than main.
Now the multi-project pipeline must deploy only those changed subfolder related changes into PRODUCTION from main branch. It should only trigger those subfolder/.gitlab-ci.yml files inside the parent child pipelines. Also, The trigger should be from the Pipeline A.
Pipeline A code:
trigger_job:
stage: prod
inherit:
variables: true
trigger:
project: project/projectB
branch: main
strategy: depend
What happens now : When the pipeline A triggers pipeline B , it is triggering all the jobs (not just the changed ones) similar to a "RUN PIPELINE" manual event.
What I want to achieve is Pipeline A -> triggers pipeline B -> In pipeline B for this trigger event it should look for changes in the subfolders in that main branch from a previous tag(passed from pipeline A).
How to combine the below into a condition ?
if: $CI_PIPELINE_SOURCE == "pipeline" #it identifies that it is triggered from pipeline
compare_to: 'refs/tags/$PREV_TAG'
and then check
changes: subfolder1/*
all under the Pipeline B's job subfolder1-job !
If you think there is a better way to achieve this, please feel free to write back. Also if you think a way to deploy from pipeline B itself(not after the MR success - as this is a manual prod deployment)
Thanks for reading this long message.