JobInjector errors when policy stage does not exist in the project in some cases

Summary

!159858 (merged) introduced a regression for certain scenarios. If multiple policy jobs are defined in a policy stage which is not declared in the project's stages, the JobInjector raises an error.

Kibana logs: https://log.gprd.gitlab.net/app/r/s/6pyZK

Workaround until the MR !164997 (merged) is merged, is to use pipeline execution policy reserved stages: .pipeline-policy-pre and .pipeline-policy-post, or to declare the stages used in the policy jobs in the project.

Relevant links

Customer impact

Customers on gitlab.com could see jobs could fail with failure - data integrity failure.

Error message:

undefined method `name' for nil:NilClass

          existing_stage = pipeline_stages_by_name[stage.name]
                                                        ^^^^^

Related tickets

  1. https://gitlab.zendesk.com/agent/tickets/564030
  2. https://gitlab.zendesk.com/agent/tickets/563035
Edited by Cleveland Bledsoe Jr