Create a failed job when rules cannot be evaluated
What
When a job's rules: raises an internal Clause::ParseError (a bad rules:exists:project, a bad rules:exists:ref, a bad rules:changes:compare_to, or a regexp over its ReDoS limits), and that job is the only one keeping its stage alive, the job is dropped and the recorded error is thrown away. The pipeline goes green with the job and the entire stage missing.
With this change the job is created as failed with allow_failure: true and a new rules_parse_failure failure reason. It never runs. The clause error is attached as a Ci::JobMessage, following the job_router_failure pattern, so the precise wording survives instead of collapsing into one generic string. The job is excluded from Processable#retryable?, since a retry does not re-evaluate rules and would run the job.
Scope stays narrow: only the silent drop changes. A stage that keeps at least one other job still reports the error and still fails pipeline creation with a config_error.
Nothing that fails today starts passing. The pipeline status stays success, because success_with_warnings resolves to success. A failed job now appears where none existed, and the pipeline reports warnings.
Behind ci_create_failed_job_on_rules_parse_error, a gitlab_com_derisk flag, default off. The new RULES_PARSE_FAILURE value appears in the CiJobFailureReason GraphQL enum regardless of the flag, but nothing can return it until the flag is on, so there is no changelog entry.
Why
Issue 606330. Broken this way since 15.3.
Jobs that need a broken job
If another job has a non-optional needs: on a job whose rules could not be evaluated, pipeline creation fails, as it does today. A job that could not be evaluated produces nothing, so depending on it is unsafe, and a deploy needing a broken security scan must not proceed. The failure now reports the rules error rather than "does not exist in the pipeline", which names the real problem. needs:optional is unchanged, because the dependent already runs without the dropped job today.
Pipelines with only broken jobs
If every job in a pipeline has a rules error, those jobs would now exist as failed jobs. The pipeline would then no longer look empty, so it would be created and pass. Today it is filtered with filtered_by_rules and not created. To keep that behavior, Chain::Populate#stage_names ignores any stage whose jobs all have rules that could not be evaluated. Such a pipeline is still treated as empty and filtered with filtered_by_rules, and for a child pipeline the trigger job still fails with downstream_pipeline_creation_failed. The check lives in Populate instead of earlier in Chain::Seed because Populate also decides whether a Pipeline Execution Policy forces creation of an empty pipeline (apply_on_empty_pipeline: always). In that case the pipeline is still created and runs the policy jobs, and the broken job shows as failed.
Jobs with environment:
A job created to carry a rules error is skipped in Chain::EnsureEnvironments. It never runs, so it needs no environment, and creating one let Environments::CreateForJobService overwrite failure_reason with environment_creation_failure, hiding the rules error the job exists to report. Chain::Create already skips the environment join row when persisted_environment is nil.
Follow-up
The logging from !257559 (merged) goes quiet once this is enabled, because the stage is no longer dropped. Seed::Pipeline#excluded_stage_errors becomes removable during flag cleanup.