I have monorepo and I want to run child pipeline depending on content of directory which has changed. In job prepare_config
I check where are latest changes, I create child config yml and in next stage's job run_child
I run child pipeline from .
The problem is, if model-gitlab-ci.yml
doesn't exist, then job run_child
fails instead of skipping due to missing artifact. I searched for solution to conditionally run job only if artifact exists instead of failing, but didn't found any solution. Maybe someone here have some idea?
.gitlab-ci.yml
:
stages:
- .pre
- build
prepare_config:
stage: .pre
tags:
- sometag
rules:
- if: $CI_COMMIT_TAG == null
when: always
changes:
- '.gitlab-ci.yml'
- 'DIR_A/**/*'
- 'DIR_B/**/*'
- 'DIR_C/**/*'
script:
- |-
files=$(git diff-tree --name-only --no-commit-id ${CI_MERGE_REQUEST_TARGET_BRANCH_SHA:-$CI_COMMIT_SHA})
echo "Files changed: $files"
for f in $files; do
if [ -d $f ]; then
sed "s/{{ MODEL_NAME }}/$f/g" .gitlab-ci-template.yml >> model-gitlab-ci.yml
fi
done
artifacts:
paths:
- "model-gitlab-ci.yml"
run_child:
stage: build
rules:
- if: $CI_COMMIT_TAG == null
when: always
needs:
- job: prepare_config
artifacts: true
trigger:
include:
- artifact: model-gitlab-ci.yml
job: prepare_config
strategy: depend