Skip to content

Fix YamlProcessor to allow needing an optional, undefined job

What does this MR do and why?

Per Issue #345377 (closed), currently you cannot use needs: to create a job dependency that points to a job added with include:local:rules. When the configuration is validated, GitLab returns undefined need: <job-name>.

This MR updates the YamlProcessor so that if a job needs an optional job that is undefined, it effectively ignores that job (so the validation passes). If the needed job does exist, then it proceeds to validate it as normal.

Screenshots or screen recordings

To reproduce the issue:

  1. Add two config files to your project:

.gitlab-ci.yml

include:
  - local: .hello-world.yml
    rules:
      - if: $RUN_HELLO_WORLD == "true"

depends-on-hello-world:
  needs: 
    - job: hello-world
      optional: true
  script:
    - echo "This job depends on Hello World!"

.hello-world.yml

hello-world:
  script:
    - echo "Hello World!"
  1. Run the pipeline with variable RUN_HELLO_WORLD=false or, equivalently, without any variables set. Observe that the pipeline fails.

Screenshot_2023-03-30_at_3.31.23_PM

How to set up and validate locally

  1. Check out this branch.
  2. Follow the steps in the previous section.
  3. Observe that you no longer get the validation error when you run the pipeline. And the pipeline runs just the one job since .hello-world.yml is not included due to the rule.

Screenshot_2023-03-30_at_3.37.51_PM

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #345377 (closed)

Edited by Leaminn Ma

Merge request reports

Loading