Dynamic pipeline fails when child pipeline runs no jobs

Summary

If a dynamically-generated child pipeline yields a pipeline with no jobs to execute, the trigger job in the parent pipeline fails with the message "downstream pipeline can not be created. No stages / jobs for this pipeline."

In our monorepo pipeline scenario, we strive for the minimal number of jobs (save time and money), so we would like to skip a child pipeline if there is nothing to do.

Steps to reproduce

The .gitlab-ci.yml file looks like this:

gen:
  stage: build
  image: alpine:latest
  script:
    - cat generated-config.yml.pipeline > generated-config.yml
  artifacts:
    paths:
      - generated-config.yml

trigger-tests:
  stage: test
  needs:
    - gen
  trigger:
    include:
      - artifact: generated-config.yml
        job: gen
    strategy: depend

The generated-config.yml.pipeline file looks like this (note the when: never rule in the job)

cat generated-config.yml.pipeline 
{
  "build1":
    {
      "image": "alpine:latest",
      "script": "echo Hello",
      "rules": [{ "when": "never" }],
    },
}

What is the current bug behavior?

The following screenshot shows the error message empty-pipeline-error

What is the expected correct behavior?

I expect the trigger job to pass when there are no jobs to run in the child pipeline.

Results of GitLab environment info

Hosted GitLab version (May 25, 2021)

Edited by 🤖 GitLab Bot 🤖