Add workflow rules to the generated gems child pipeline

What does this MR do?

Fixes the gems:test failures in non-canonical projects that started with !263286 (merged), reported in !263286 (comment 4261302981).

gems:test fails there with:

downstream pipeline can not be created. The resulting pipeline would have been empty. Review the rules configuration.

Cause

gems:dependency_graph generates the child pipeline that gems:test triggers. The generated jobs have no rules, and the generated config has no workflow:rules. Jobs like that get the default only: [branches, tags]. The child of a merge request pipeline is not a branch pipeline, so no job matches and the child pipeline is empty.

The old gems <name> jobs did not have this problem: they were in the root pipeline and had their own rules.

Why we did not see it in gitlab-org/gitlab

The project setting Skip branch pipelines for merge requests (ci_skip_branch_pipelines_for_mrs) was hiding the problem. When it is on, jobs without rules lose the only default (skip_branch_pipelines_for_mrs? in lib/gitlab/ci/config/entry/processable.rb), so they also run in the child of a merge request pipeline.

The setting is not the same in all our projects:

Project ci_skip_branch_pipelines_for_mrs gems:test in merge request pipelines
gitlab-org/gitlab true passes
gitlab-org/security/gitlab false fails
gitlab-org/gitlab-foss false fails when the job runs

The generator, the CI config and the generated YAML are identical in a failing security pipeline (https://gitlab.com/gitlab-org/security/gitlab/-/pipelines/3081486478) and in a passing canonical pipeline (https://gitlab.com/gitlab-org/gitlab/-/pipelines/3077553562). Only the project setting is different.

Fix

The generator adds workflow:rules with when: always to the generated pipeline. With workflow:rules, the jobs do not get the only default, with the setting on or off. gems/gem.gitlab-ci.yml already uses the same pattern for the pipeline of each gem.

workflow:
  rules:
  - when: always
gems action_dispatch-draw_all:
  trigger:
    include: gems/action_dispatch-draw_all/.gitlab-ci.yml
    strategy: depend

Verification

  • The generator spec passes locally.
  • Not verified: a pipeline in a project with the setting off. The pipeline of this MR runs gems:test, because the MR changes the generator, but gitlab-org/gitlab passed before the fix too. A merge request pipeline in gitlab-org/security/gitlab that changes a gem or a file in rubocop/ is the real check.

19-6-stable-ee has the same problem and needs a backport of this MR.

Checklist

Pre-merge

Consider the effect of the changes in this merge request on the following:

  • Different pipeline types: the rules of gems:dependency_graph and gems:test do not change. Only the generated child pipeline changes.
  • Non-canonical projects:
    • gitlab-foss: setting off, this MR fixes it.
    • security: setting off, this MR fixes it.
    • dev: setting not checked. The generated pipeline no longer depends on it.
    • personal forks: the setting is off by default, this MR fixes it.
  • Pipeline performance: no change.

If new jobs are added: no new jobs.

Post-merge

Edited by Luke Duncalfe

Merge request reports

Loading
Loading