gitlab-ci-validator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGitLab CI/CD Validator
GitLab CI/CD 验证工具
Comprehensive toolkit for validating, linting, testing, and securing configurations.
.gitlab-ci.yml一款用于验证、检查、测试和加固配置的综合工具集。
.gitlab-ci.ymlTrigger Phrases
触发场景
Use this skill when requests include intent like:
- "Validate this "
.gitlab-ci.yml - "Why is this GitLab pipeline failing?"
- "Run a security review for our GitLab CI"
- "Check pipeline best practices"
- "Lint GitLab CI config before merge"
当需求包含以下意图时,可使用本技能:
- "验证这份"
.gitlab-ci.yml - "为什么这个GitLab流水线运行失败?"
- "为我们的GitLab CI执行安全审计"
- "检查流水线最佳实践"
- "合并前检查GitLab CI配置"
Setup And Prerequisites (Run First)
安装与前提条件(先执行)
All commands below assume repository root as current working directory.
bash
undefined以下所有命令均假设当前工作目录为仓库根目录。
bash
undefinedEnsure validator scripts are executable
Ensure validator scripts are executable
chmod +x devops-skills-plugin/skills/gitlab-ci-validator/scripts/.sh
devops-skills-plugin/skills/gitlab-ci-validator/scripts/.py
devops-skills-plugin/skills/gitlab-ci-validator/scripts/.py
chmod +x devops-skills-plugin/skills/gitlab-ci-validator/scripts/.sh
devops-skills-plugin/skills/gitlab-ci-validator/scripts/.py
devops-skills-plugin/skills/gitlab-ci-validator/scripts/.py
Required runtime
Required runtime
python3 --version
Use one canonical command path for orchestration:
```bash
VALIDATOR="bash devops-skills-plugin/skills/gitlab-ci-validator/scripts/validate_gitlab_ci.sh"Optional local execution tooling (for ):
--test-onlybash
bash devops-skills-plugin/skills/gitlab-ci-validator/scripts/install_tools.shpython3 --version
使用统一的命令路径来调用工具:
```bash
VALIDATOR="bash devops-skills-plugin/skills/gitlab-ci-validator/scripts/validate_gitlab_ci.sh"可选的本地执行工具(用于参数):
--test-onlybash
bash devops-skills-plugin/skills/gitlab-ci-validator/scripts/install_tools.shQuick Start Commands
快速开始命令
bash
undefinedbash
undefined1) Full validation (syntax + best practices + security)
1) Full validation (syntax + best practices + security)
$VALIDATOR .gitlab-ci.yml
$VALIDATOR .gitlab-ci.yml
2) Syntax and schema only (required first gate)
2) Syntax and schema only (required first gate)
$VALIDATOR .gitlab-ci.yml --syntax-only
$VALIDATOR .gitlab-ci.yml --syntax-only
3) Best-practices only (recommended)
3) Best-practices only (recommended)
$VALIDATOR .gitlab-ci.yml --best-practices
$VALIDATOR .gitlab-ci.yml --best-practices
4) Security only (required before merge)
4) Security only (required before merge)
$VALIDATOR .gitlab-ci.yml --security-only
$VALIDATOR .gitlab-ci.yml --security-only
5) Optional local pipeline structure test (needs gitlab-ci-local + Docker)
5) Optional local pipeline structure test (needs gitlab-ci-local + Docker)
$VALIDATOR .gitlab-ci.yml --test-only
$VALIDATOR .gitlab-ci.yml --test-only
6) Strict mode (treat best-practice warnings as failure)
6) Strict mode (treat best-practice warnings as failure)
$VALIDATOR .gitlab-ci.yml --strict
undefined$VALIDATOR .gitlab-ci.yml --strict
undefinedDeterministic Validation Workflow
标准化验证流程
Follow these gates in order:
- Run Quick Start command (
2).--syntax-only - If syntax fails, stop and fix errors before continuing.
- Run Quick Start command (
3) and apply relevant improvements.--best-practices - Run Quick Start command (
4) and fix all--security-only/criticalfindings before merge.high - Optionally run Quick Start command (
5) for local execution checks.--test-only - Run Quick Start command (
6) for final merge gate.--strict
Required gates: syntax + security.
Recommended gate: best practices.
Optional gate: local execution test.
按顺序执行以下检查步骤:
- 执行快速开始命令(
2)。--syntax-only - 如果语法检查失败,请停止并修复错误后再继续。
- 执行快速开始命令(
3)并应用相关优化建议。--best-practices - 执行快速开始命令(
4),在合并前修复所有--security-only(严重)/critical(高危)问题。high - 可选执行快速开始命令(
5)进行本地执行检查。--test-only - 执行快速开始命令(
6)作为最终合并检查。--strict
必须执行的检查:语法检查 + 安全检查。
推荐执行的检查:最佳实践检查。
可选检查:本地执行测试。
Rule Severity Rationale And Documentation Links
规则严重程度说明及文档链接
Severity Model
严重程度模型
- : Direct credential/secret exposure or high-confidence compromise path. Block merge.
critical - : Exploitable unsafe behavior or strong security regression. Fix before merge.
high - : Security hardening gap with realistic risk. Track and fix soon.
medium - /
low: Optimization or maintainability improvement.suggestion
- (严重):直接暴露凭证/密钥或存在高风险攻击路径。阻止合并。
critical - (高危):存在可被利用的不安全行为或严重安全倒退。合并前必须修复。
high - (中危):存在安全加固缺口且有实际风险。需跟踪并尽快修复。
medium - (低危)/
low(建议):优化或可维护性改进建议。suggestion
Rule Classes And Why They Matter
规则类别及其重要性
- Syntax rules (,
yaml-syntax,job-stage-undefined): prevent pipeline parse and dependency failures.dependencies-undefined-job - Best-practice rules (,
cache-missing,artifact-no-expiration): reduce runtime cost and improve pipeline throughput.dag-optimization - Security rules (,
hardcoded-password,curl-pipe-bash): reduce credential leaks and supply-chain risk.include-remote-unverified
- 语法规则(、
yaml-syntax、job-stage-undefined):防止流水线解析失败和依赖错误。dependencies-undefined-job - 最佳实践规则(、
cache-missing、artifact-no-expiration):降低运行成本并提升流水线吞吐量。dag-optimization - 安全规则(、
hardcoded-password、curl-pipe-bash):减少凭证泄露和供应链风险。include-remote-unverified
References
参考资料
- Local syntax reference:
devops-skills-plugin/skills/gitlab-ci-validator/docs/gitlab-ci-reference.md - Local best practices:
devops-skills-plugin/skills/gitlab-ci-validator/docs/best-practices.md - Local common issues:
devops-skills-plugin/skills/gitlab-ci-validator/docs/common-issues.md - GitLab CI YAML reference: https://docs.gitlab.com/ee/ci/yaml/
- GitLab CI/CD components: https://docs.gitlab.com/ee/ci/components/
- GitLab pipeline security guidance: https://docs.gitlab.com/ee/ci/pipelines/settings.html
- 本地语法参考文档:
devops-skills-plugin/skills/gitlab-ci-validator/docs/gitlab-ci-reference.md - 本地最佳实践文档:
devops-skills-plugin/skills/gitlab-ci-validator/docs/best-practices.md - 本地常见问题文档:
devops-skills-plugin/skills/gitlab-ci-validator/docs/common-issues.md - GitLab CI YAML 官方参考:https://docs.gitlab.com/ee/ci/yaml/
- GitLab CI/CD 组件:https://docs.gitlab.com/ee/ci/components/
- GitLab 流水线安全指南:https://docs.gitlab.com/ee/ci/pipelines/settings.html
Fallbacks For Tool Or Environment Constraints
工具或环境受限的替代方案
- Missing :
python3- Behavior: validator cannot run.
- Fallback: install Python 3 and rerun.
- Missing :
PyYAML- Behavior: auto-creates
python_wrapper.shand installs.venvwhen possible.pyyaml - Fallback in restricted/offline environments: pre-install from an internal mirror, then rerun.
pyyaml
- Behavior:
- Missing ,
gitlab-ci-local, ornode:docker- Behavior: reports warning/failure.
--test-only - Fallback: skip local execution testing and continue with syntax/best-practice/security gates.
- Behavior:
- No execute permission on scripts:
- Behavior: shell permission errors.
- Fallback: rerun the setup command from the Setup section.
chmod
- 缺少:
python3- 现象:验证工具无法运行。
- 替代方案:安装Python 3后重新运行。
- 缺少:
PyYAML- 现象:会尝试自动创建
python_wrapper.sh并安装.venv。pyyaml - 受限/离线环境下的替代方案:从内部镜像预安装后重新运行。
pyyaml
- 现象:
- 缺少、
gitlab-ci-local或node:docker- 现象:参数会返回警告/失败。
--test-only - 替代方案:跳过本地执行测试,继续执行语法/最佳实践/安全检查。
- 现象:
- 脚本无执行权限:
- 现象:出现Shell权限错误。
- 替代方案:重新执行安装部分的命令。
chmod
Examples
示例
Example 1: New Pipeline Validation
示例1:新流水线验证
bash
$VALIDATOR examples/basic-pipeline.gitlab-ci.yml --syntax-only
$VALIDATOR examples/basic-pipeline.gitlab-ci.yml --security-onlybash
$VALIDATOR examples/basic-pipeline.gitlab-ci.yml --syntax-only
$VALIDATOR examples/basic-pipeline.gitlab-ci.yml --security-onlyExample 2: Pre-Merge Hard Gate
示例2:合并前强制检查
bash
$VALIDATOR .gitlab-ci.yml --strictbash
$VALIDATOR .gitlab-ci.yml --strictExample 3: CI Integration
示例3:CI集成
yaml
stages:
- validate
validate_gitlab_ci:
stage: validate
script:
- chmod +x devops-skills-plugin/skills/gitlab-ci-validator/scripts/*.sh devops-skills-plugin/skills/gitlab-ci-validator/scripts/*.py
- bash devops-skills-plugin/skills/gitlab-ci-validator/scripts/validate_gitlab_ci.sh .gitlab-ci.yml --strictyaml
stages:
- validate
validate_gitlab_ci:
stage: validate
script:
- chmod +x devops-skills-plugin/skills/gitlab-ci-validator/scripts/*.sh devops-skills-plugin/skills/gitlab-ci-validator/scripts/*.py
- bash devops-skills-plugin/skills/gitlab-ci-validator/scripts/validate_gitlab_ci.sh .gitlab-ci.yml --strictIndividual Validators (Advanced)
独立验证器(进阶用法)
bash
undefinedbash
undefinedSyntax validator (via wrapper for PyYAML fallback)
Syntax validator (via wrapper for PyYAML fallback)
bash devops-skills-plugin/skills/gitlab-ci-validator/scripts/python_wrapper.sh
devops-skills-plugin/skills/gitlab-ci-validator/scripts/validate_syntax.py .gitlab-ci.yml
devops-skills-plugin/skills/gitlab-ci-validator/scripts/validate_syntax.py .gitlab-ci.yml
bash devops-skills-plugin/skills/gitlab-ci-validator/scripts/python_wrapper.sh
devops-skills-plugin/skills/gitlab-ci-validator/scripts/validate_syntax.py .gitlab-ci.yml
devops-skills-plugin/skills/gitlab-ci-validator/scripts/validate_syntax.py .gitlab-ci.yml
Best-practices validator
Best-practices validator
bash devops-skills-plugin/skills/gitlab-ci-validator/scripts/python_wrapper.sh
devops-skills-plugin/skills/gitlab-ci-validator/scripts/check_best_practices.py .gitlab-ci.yml
devops-skills-plugin/skills/gitlab-ci-validator/scripts/check_best_practices.py .gitlab-ci.yml
bash devops-skills-plugin/skills/gitlab-ci-validator/scripts/python_wrapper.sh
devops-skills-plugin/skills/gitlab-ci-validator/scripts/check_best_practices.py .gitlab-ci.yml
devops-skills-plugin/skills/gitlab-ci-validator/scripts/check_best_practices.py .gitlab-ci.yml
Security validator
Security validator
bash devops-skills-plugin/skills/gitlab-ci-validator/scripts/python_wrapper.sh
devops-skills-plugin/skills/gitlab-ci-validator/scripts/check_security.py .gitlab-ci.yml
devops-skills-plugin/skills/gitlab-ci-validator/scripts/check_security.py .gitlab-ci.yml
undefinedbash devops-skills-plugin/skills/gitlab-ci-validator/scripts/python_wrapper.sh
devops-skills-plugin/skills/gitlab-ci-validator/scripts/check_security.py .gitlab-ci.yml
devops-skills-plugin/skills/gitlab-ci-validator/scripts/check_security.py .gitlab-ci.yml
undefinedDone Criteria
完成标准
- Frontmatter and
nameunchanged.description - One canonical orchestrator path is used consistently.
- Setup and prerequisites appear before workflow/use examples.
chmod - Quick-start and workflow are non-duplicative (workflow references quick-start gates).
- Severity rationale and rule-to-doc references are explicit.
- Fallback behavior is documented for missing tools and constrained environments.
- Examples are executable from repository root.
- 前端部分的和
name保持不变。description - 统一使用标准化的工具调用路径。
- 安装步骤和前提条件位于流程/示例之前。
chmod - 快速开始命令与流程无重复(流程引用快速开始的检查步骤)。
- 明确说明规则严重程度的依据及对应文档链接。
- 记录工具缺失或环境受限时的替代方案。
- 示例可从仓库根目录直接执行。
Notes
注意事项
- This skill validates configuration and static patterns; it does not execute production pipelines.
- Use or GitLab CI Lint for runtime behavior confirmation.
gitlab-ci-local
- 本技能仅验证配置和静态模式,不执行生产流水线。
- 如需确认运行时行为,请使用或GitLab CI Lint工具。
gitlab-ci-local