YAML Schema for CI/CD Pipeline Configuration
Learn how to generate YAML Schema definitions for CI/CD pipeline configurations from JSON. Covers job definitions, step sequences, environment variables, conditional execution, and matrix strategies.
Detailed Explanation
CI/CD Pipeline Configuration Schema
CI/CD pipeline files (GitHub Actions, GitLab CI, Azure Pipelines) follow predictable patterns. Converting a sample pipeline JSON to YAML Schema creates a validation layer that catches configuration errors before commits.
Example Pipeline JSON
{
"name": "Build and Deploy",
"on": {
"push": {
"branches": ["main", "develop"]
},
"pull_request": {
"branches": ["main"]
}
},
"jobs": {
"build": {
"runsOn": "ubuntu-latest",
"steps": [
{
"name": "Checkout",
"uses": "actions/checkout@v4"
},
{
"name": "Setup Node",
"uses": "actions/setup-node@v4",
"with": {
"nodeVersion": "20"
}
},
{
"name": "Install",
"run": "npm ci"
},
{
"name": "Test",
"run": "npm test"
}
]
}
}
}
Generated YAML Schema
type: object
properties:
name:
type: string
description: Workflow name displayed in the Actions tab
on:
type: object
properties:
push:
type: object
properties:
branches:
type: array
items:
type: string
pull_request:
type: object
properties:
branches:
type: array
items:
type: string
jobs:
type: object
patternProperties:
"^[a-z][a-z0-9_-]*$":
type: object
properties:
runsOn:
type: string
enum:
- ubuntu-latest
- ubuntu-22.04
- macos-latest
- windows-latest
steps:
type: array
items:
type: object
properties:
name:
type: string
uses:
type: string
pattern: "^[a-zA-Z0-9-]+/[a-zA-Z0-9-]+@.+$"
run:
type: string
with:
type: object
oneOf:
- required: [uses]
- required: [run]
minItems: 1
required:
- runsOn
- steps
required:
- name
- on
- jobs
Key Schema Patterns for CI/CD
Step type validation -- Each step must have either uses (action) or run (script), but not both:
oneOf:
- required: [uses]
properties:
run: false
- required: [run]
properties:
uses: false
Matrix strategy:
strategy:
type: object
properties:
matrix:
type: object
patternProperties:
".*":
type: array
items:
type: [string, integer]
Environment variables:
env:
type: object
patternProperties:
"^[A-Z][A-Z0-9_]*$":
type: string
Conditional Execution
if:
type: string
description: >
GitHub Actions expression that determines
whether the step runs.
examples:
- "github.ref == 'refs/heads/main'"
- "always()"
- "success()"
Benefits of CI/CD Schema Validation
- Catch syntax errors locally before pushing
- IDE autocompletion with schema-aware editors
- Prevent typos in runner names, action references
- Enforce standards across team repositories
Use Case
Teams managing dozens of repositories need consistent CI/CD configurations. A YAML schema for pipeline files enables IDE autocompletion in VS Code, catches invalid runner names or missing required fields before git push, and serves as documentation for the team's CI/CD conventions.
Try It — JSON to YAML Schema
Related Topics
Generate YAML Schema for GitHub Actions Workflows
Real-World Configs
Generate YAML Schema for Docker Compose Files
Real-World Configs
Generate YAML Schema for Kubernetes Configuration
Real-World Configs
Use Regex Pattern Matching in YAML Schema
Advanced Patterns
Define Required Fields in YAML Schema
Validation Rules