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:
- 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!"
- Run the pipeline with variable
RUN_HELLO_WORLD=falseor, equivalently, without any variables set. Observe that the pipeline fails.
How to set up and validate locally
- Check out this branch.
- Follow the steps in the previous section.
- 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.ymlis not included due to the rule.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #345377 (closed)
Edited by Leaminn Ma

