Reputation: 375
In Gitlab I am trying to trigger child pipeline from parent pipeline. The child pipeline is within the same project under subdirectory. However, while triggering at the time of merge request event it is giving error "downstream pipeline cannot be created, No stages/jobs for this pipeline"
Folder structure:
Parent pipeline:
trigger_servicename:
stage: triggers
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "dev"'
changes:
- app-notifier/*
when: always
trigger:
include: servicename/.gitlab-ci.yml
strategy: depend
Child pipeline:
image:
name: registry.gitlab.com/who-docker/aws-cli:latest
entrypoint:
- /usr/bin/env
- 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
stages:
-build
build:
stage: build
script:
- echo "run build..."
test:
stage: test
script:
- echo "run test...."
Upvotes: 4
Views: 18948
Reputation: 31
A child pipeline is not triggered automatically. The jobs in the child YAMl file are matched agains the rules section of the jobs. To add a job to the task list, add a rule to the workflow.
For example:
Parent gitlab configuration
trigger_servicename:
trigger:
include: servicename/.gitlab-ci.yml
strategy: depend
Child gitlab configuration
child_service:
image: my-image-name
rules:
- if: '$CI_PIPELINE_SOURCE == "parent_pipeline"'
Upvotes: 2
Reputation: 2730
In general you will get the error message "downstream pipeline cannot be created, No stages/jobs for this pipeline" when there is no rule that matches any of the jobs in the child pipeline. Rules from upstream pipelines will be inherited in child pipelines.
Looking at your example the rule if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "dev"'
is inherited to the child pipeline. This rule does not match in the child pipeline, because $CI_PIPELINE_SOURCE
in a child pipeline is trigger
, and not the one from the upstream pipeline. Consequently, no jobs are available for gitlab to execute.
If you add
workflow:
rules:
- when: always
to your child pipeline it will work. Modify the rules accordingly if required.
Upvotes: 28
Reputation: 2549
For a monorepo with multiple projects I actually did something like:
nameofjob:
stage: trigger
trigger:
include:
- artifact: folder/.gitlab-ci.yml
strategy: depend
For an external project -
include:
- project: 'my-group/my-pipeline-library'
ref: 'main'
file: '/path/to/child-pipeline.yml'
https://docs.gitlab.com/ee/ci/pipelines/parent_child_pipelines.html
Upvotes: 0