Add error message for cyclic dependencies in pipeline execution policies

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Problem

When using pipeline execution policies, it's possible to inadvertently create a cyclic dependency between jobs, leading to a deadlock situation. Currently, this results in jobs being stuck in a 'created' state without any warnings or error messages.

Example scenario

  1. In the project's .gitlab-ci.yml file:
    • Stage 1: build
    • Stage 2: test
  2. In the pipeline execution policy:
    • Inject a policy with a job in the 'build' stage that needs a job from the 'test' stage

Current behavior

Jobs become stuck in a 'created' state without any warnings or error messages, making it difficult for users to identify and resolve the issue.

Proposed solution

Implement an error message that alerts users when a cyclic dependency is detected between pipeline execution policy jobs and the jobs defined in the GitLab CI YAML. The error should specifically identify when:

  1. A pipeline execution policy job is defined in a later stage
  2. That job has a 'needs:' dependency on a job defined in the GitLab CI YAML
  3. The dependent job is configured to execute in a stage before the stage defined in the policy's job

Expected outcome

Users will receive a clear error message explaining the cyclic dependency, allowing them to quickly identify and resolve the issue in their pipeline configuration.

Edited by 🤖 GitLab Bot 🤖