Search code examples
gitlabgitlab-cigitlab-ci-trigger

Gitlab CI multi project pipeline


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:

  • Namespace/Project/.gitlab-ci.yml (parent pipeline)
  • Namespace/Project/servicename/.gitlab-ci.yml (child pipeline)

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...."

Solution

  • 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