feat(linter): rules:needs: validation (GL044)
Add GL044 to validate jobs listed in rules:needs: overrides (GitLab CI 16.4+). rules:needs: lets a specific rule override the job's top-level needs: list; any referenced job must exist in the pipeline. Unknown jobs produce an error; optional: true entries produce a warning, matching the GL027 behaviour for top-level needs:. Cross-pipeline needs and skipped jobs (when a context is active) are excluded from checking. Implementation: - model.Rule gains a Needs []any field (yaml:"needs") - checkRulesNeeds(p, skipped) added to needs.go; wired into Lint - GL044 / RuleRulesNeedsUnknown added to rules.go and explain.go - 6 unit tests + 2 testdata fixtures; task validate updated Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -816,4 +816,41 @@ my-job:
|
||||
my-job:
|
||||
script: echo hi`,
|
||||
},
|
||||
|
||||
RuleRulesNeedsUnknown: {
|
||||
Title: "'rules:needs:' references unknown job",
|
||||
Severity: Error,
|
||||
Description: "A job listed in a rule's 'needs:' override does not exist in " +
|
||||
"the pipeline. 'rules:needs:' (GitLab CI 16.4+) overrides the top-level " +
|
||||
"'needs:' list when that specific rule matches. GitLab will refuse to " +
|
||||
"create the pipeline if any referenced job is missing.",
|
||||
Example: `stages: [build, test]
|
||||
|
||||
build:
|
||||
stage: build
|
||||
script: make
|
||||
|
||||
test:
|
||||
stage: test
|
||||
script: make test
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == "main"
|
||||
needs: [build, lint] # lint does not exist`,
|
||||
Fix: `stages: [build, test]
|
||||
|
||||
lint:
|
||||
stage: build
|
||||
script: make lint
|
||||
|
||||
build:
|
||||
stage: build
|
||||
script: make
|
||||
|
||||
test:
|
||||
stage: test
|
||||
script: make test
|
||||
rules:
|
||||
- if: $CI_COMMIT_BRANCH == "main"
|
||||
needs: [build, lint]`,
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user