Back to BlogCase Studies

GitLab CI YAML Validation Made Simple - Test Before You Push

YAMLforge Team
13 min read
yamljsondevops
Cover image for GitLab CI YAML Validation Made Simple - Test Before You Push

GitLab CI YAML Validation Made Simple - Test Before You Push

You push your code, wait for the pipeline to start, and... immediate failure. Syntax error on line 42. Again. That's fifteen minutes you'll never get back.

⚑ Work Faster: YAMLforge Pro removes the 10/day limit - convert as many files as you need.

β†’ Related: Convert YAML to JSON Instantly (Free Online Tool)

Meet YF-kun πŸ€– β€” I'm your guide through this article! I've debugged more YAML indentation issues than I care to admit, and I'll pop in whenever there's something important or just plain interesting to share. Let's make sure your GitLab CI configs work the first time.

πŸ˜… YF-kun: Config file debugging at 2am hits different. We've all been there.
πŸ˜… YF-kun: I once spent two hours debugging a pipeline only to discover I'd used tabs instead of spaces. The error message? Completely unhelpful. YAML is picky like that.

What is GitLab CI YAML Validation?

GitLab CI uses a .gitlab-ci.yml file to define your pipelineβ€”what jobs run, in what order, and under what conditions. This YAML file controls everything from running tests to deploying to production.

Validation checks if your YAML syntax is correct and follows GitLab's specific schema rules. You can catch errors like missing keys, wrong indentation, invalid job names, or incorrect stage definitions before they break your actual pipeline.

Think of it like a spell-checker for your CI configuration. It won't tell you if your logic is right, but it'll definitely tell you if you forgot a colon or indented something wrong.

πŸ€” YF-kun: GitLab's YAML parser is actually pretty strict. Some things that work in regular YAML won't fly in a CI config. For example, you can't use anchors across different files with include. Learned that one the hard way.
YAML server: port: 8080 host: localhost Convert JSON {"server": { "port": 8080, "host": "localhost"}}

How to Validate Your GitLab CI YAML

πŸ”— API Access: Integrate YAML conversion into your workflow with Pro API.

Method 1: GitLab's Built-in CI Lint Tool

GitLab provides a dedicated validation tool at https://gitlab.com/[your-project]/-/ci/lint. You can access it from your project's CI/CD settings.

Steps:

  1. Navigate to your GitLab project
  2. Go to CI/CD β†’ Editor or CI/CD β†’ Pipelines β†’ CI Lint
  3. Paste your YAML content
  4. Click Validate

The tool will show you:

  • βœ… Syntax errors with line numbers
  • βœ… Expanded configuration (with includes resolved)
  • βœ… What your pipeline stages and jobs will look like
πŸ’‘ YF-kun: The CI Lint tool actually simulates your entire config. It resolves all your extends, include statements, and variable substitutions. Super helpful when you're working with complex multi-file setups.

Method 2: Using the GitLab API

For automation or local validation, you can hit GitLab's API directly:

curl --header "Content-Type: application/json" \
     --header "PRIVATE-TOKEN: your_token" \
     --data '{"content": "your-yaml-here"}' \
     "https://gitlab.com/api/v4/ci/lint"

This returns JSON with validation status and any errors found.

πŸš€ YF-kun: You can build this into pre-commit hooks. Validate locally before pushing, and you'll never break the pipeline for your teammates again. They'll love you for it.

Method 3: Using YAMLforge for Quick Syntax Checks

πŸ’‘ Need more than 10 conversions per day? Pro users get unlimited access.

While GitLab's tools check GitLab-specific rules, sometimes you just need to know if your YAML syntax is valid at all. YAMLforge can help with that:

# Example .gitlab-ci.yml
stages:
  - build
  - test
  - deploy

build_job:
  stage: build
  script:
    - echo "Building the app"
    - npm install
    - npm run build
  artifacts:
    paths:
      - dist/

test_job:
  stage: test
  script:
    - npm test
  coverage: '/Coverage: \d+\.\d+%/'

deploy_job:
  stage: deploy
  script:
    - ./deploy.sh
  only:
    - main

Convert to JSON with YAMLforge to spot structural issues:

{
  "stages": [
    "build",
    "test",
    "deploy"
  ],
  "build_job": {
    "stage": "build",
    "script": [
      "echo \"Building the app\"",
      "npm install",
      "npm run build"
    ],
    "artifacts": {
      "paths": [
        "dist/"
      ]
    }
  },
  "test_job": {
    "stage": "test",
    "script": [
      "npm test"
    ],
    "coverage": "/Coverage: \\d+\\.\\d+%/"
  },
  "deploy_job": {
    "stage": "deploy",
    "script": [
      "./deploy.sh"
    ],
    "only": [
      "main"
    ]
  }
}
🎯 YF-kun: If YAMLforge can't parse your YAML into valid JSON, GitLab definitely won't be able to use it. It's a quick sanity check before you even hit the CI Lint tool.
Step 1 Paste YAML Step 2 Click Validate Step 3 Fix Errors:Push with Confidence

Common GitLab CI YAML Mistakes

1. Indentation Errors

YAML is whitespace-sensitive. Mix up your indentation and everything breaks:

# ❌ Wrong - inconsistent indentation
build_job:
  stage: build
  script:
   - echo "Hello"  # Only 1 space instead of 2
    - npm install  # 4 spaces - inconsistent!
# βœ… Correct - consistent 2-space indentation
build_job:
  stage: build
  script:
    - echo "Hello"
    - npm install
⚠️ YF-kun: Use spaces, never tabs. Most editors let you configure this. VS Code's YAML extension will yell at you if you mess this up. Trust me, enable it.

2. The Norway Problem in CI Configs

Remember, YAML interprets certain strings as booleans:

# ❌ This breaks in unexpected ways
variables:
  DEPLOY_TO: NO  # Becomes false!
  ENABLE_CACHE: YES  # Becomes true!
  DEBUG_MODE: OFF  # Also becomes false!

GitLab will read these as boolean values, not strings. Your deploy script expecting "NO" as a string will get false instead.

β†’ See also: Best Kubernetes YAML Validators for Error-Free Deployments

# βœ… Quote them to preserve as strings
variables:
  DEPLOY_TO: "NO"
  ENABLE_CACHE: "YES"
  DEBUG_MODE: "OFF"
πŸ˜… YF-kun: The Norway Problem strikes again. I once deployed to the wrong environment because someone set PRODUCTION: NO without quotes. The deployment script read it as false (which is truthy in bash), and... yeah. Production got the dev build. Fun times.
The Norway Problem country: NO YAML parses this as: false (boolean) NO, Yes, Off = booleans! YAMLforge Solution country: "NO" Correctly preserved as: "NO" (string) Smart detection & quoting

3. Invalid Stage References

# ❌ Job references a stage that doesn't exist
stages:
  - build
  - test

deploy_job:
  stage: deploy  # Error! 'deploy' stage not defined
  script:
    - ./deploy.sh
# βœ… All stages must be declared first
stages:
  - build
  - test
  - deploy  # Now it's defined

deploy_job:
  stage: deploy
  script:
    - ./deploy.sh

4. Incorrect only and except Syntax

# ❌ Wrong - only expects an array
deploy_job:
  stage: deploy
  only: main  # This won't work
  script:
    - ./deploy.sh
# βœ… Correct - use array syntax
deploy_job:
  stage: deploy
  only:
    - main  # Proper array format
  script:
    - ./deploy.sh

Or better yet, use the newer rules syntax:

# βœ… Modern approach with rules
deploy_job:
  stage: deploy
  script:
    - ./deploy.sh
  rules:
    - if: '$CI_COMMIT_BRANCH == "main"'
πŸ’‘ YF-kun: GitLab's moving away from only and except toward rules. It's more powerful and way more readable. You can combine conditions with && and ||, check variables, file changes, all sorts of stuff.

Advanced Validation Techniques

Pre-commit Hooks with gitlab-ci-lint

Install the gitlab-ci-lint CLI tool:

npm install -g gitlab-ci-lint

Create a .git/hooks/pre-commit script:

#!/bin/bash

if [ -f .gitlab-ci.yml ]; then
  echo "Validating .gitlab-ci.yml..."
  gitlab-ci-lint .gitlab-ci.yml
  if [ $? -ne 0 ]; then
    echo "❌ GitLab CI validation failed. Fix errors before committing."
    exit 1
  fi
  echo "βœ… GitLab CI validation passed"
fi

Now you can't commit broken configs even if you wanted to.

Schema Validation in Your Editor

Most modern editors support YAML schema validation. For VS Code, install the "YAML" extension by Red Hat, then add to your settings:

{
  "yaml.schemas": {
    "https://gitlab.com/gitlab-org/gitlab/-/rawithmaster/app/assets/javascripts/editor/schema/ci.json": ".gitlab-ci.yml"
  }
}

You'll get real-time validation, autocomplete, and inline documentation as you type.

πŸš€ YF-kun: This changed my life. Autocomplete for GitLab CI keywords? Hover documentation for job properties? Yes please. You catch 90% of errors before you even save the file.

Privacy and Security Considerations

When validating CI configs, keep security in mind:

  • Never paste sensitive data into public validation tools
  • Remove secrets before validation (use placeholder values)
  • Use GitLab's built-in tools for configs with private information
  • YAMLforge processes locally - your data never leaves your browser
🎯 YF-kun: Seriously, don't paste your production API keys into random online validators. I've seen it happen. Use GitLab's own tools for anything sensitive, or use YAMLforge since it's fully client-side. Your secrets stay secret.

Comparison: GitLab CI Lint vs. General YAML Validators

FeatureGitLab CI LintYAMLforgeGeneric YAML Validator
YAML Syntax Checkβœ“βœ“βœ“
GitLab Schema Validationβœ“βœ—βœ—
Resolves includeβœ“βœ—βœ—
Expands Variablesβœ“βœ—βœ—
Client-side Processingβœ—βœ“Varies
Works Offlineβœ—βœ“βœ—
Norway Problem Detectionβœ—βœ“βœ—
Best ForFinal validationSyntax checksBasic parsing

Use GitLab's CI Lint for comprehensive validation. Use YAMLforge for quick syntax checks and privacy-sensitive configs. Use both for the best workflow.

πŸŽ‰ YF-kun: That's itβ€”you've got this. Go build something cool.
Why YAMLforge? βœ“ 100% Client-side βœ“ Norway Problem Fixed βœ“ Free 10/day βœ“ Date Safe Mode βœ“ Schema Validation βœ“ Pro: $9/month

Frequently Asked Questions

How do I validate my GitLab CI YAML file?
Use GitLab's built-in CI Lint tool at https://gitlab.com/[your-project]/-/ci/lint. Paste your YAML and click Validate. It checks both syntax and GitLab-specific schema rules.

Can I validate GitLab CI YAML offline?
Yes. Install the gitlab-ci-lint npm package for local validation, or use editor plugins like VS Code's YAML extension with GitLab's schema for real-time validation as you code.

What's the difference between YAML validation and GitLab CI validation?
YAML validation checks if your syntax is correct (indentation, colons, dashes). GitLab CI validation also checks if you're following GitLab's schemaβ€”valid job names, stage references, proper rules syntax, etc.

Why does my valid YAML fail in GitLab CI?
GitLab has specific requirements beyond basic YAML syntax. Common issues: undefined stages, invalid job keywords, incorrect only/except arrays, or using unsupported YAML features like anchors across included files.

Is it safe to paste my CI config into online validators?
For configs without secrets, yes. But remove any sensitive tokens, passwords, or API keys first. Better yet, use GitLab's own tools or client-side validators like YAMLforge that never send your data to a server.

β†’ Learn more: Convert YAML to JSON While Keeping Anchors Intact

What is the Norway Problem in GitLab CI?
YAML converts NO, YES, ON, and OFF to booleans unless quoted. In CI configs, this can break environment variables or conditional logic. Always quote these values: DEPLOY: "NO" instead of DEPLOY: NO.

Start Validating Smarter Today

You now know how to validate GitLab CI YAML files like a pro:

  • βœ… Use GitLab's CI Lint tool for comprehensive checks
  • βœ… Catch syntax errors early with local validation
  • βœ… Avoid common mistakes like the Norway Problem
  • βœ… Set up pre-commit hooks to prevent broken configs
  • βœ… Use editor schemas for real-time validation
πŸŽ‰ YF-kun: You're all set! No more broken pipelines from silly syntax errors. And hey, if you need to quickly check YAML syntax or convert formats, YAMLforge has your backβ€”totally free, no signup needed. Now go forth and build reliable pipelines!
Ready to try it? 10 free conversions/day Start Free β†’

Need unlimited conversions? Try YAMLforge Pro - unlimited access, API, priority support, and team features. $9/month with 30-day money-back guarantee.

Y

YAMLforge Team

Technical Content Team

The YAMLforge team is passionate about helping developers build better software.

Try YAMLforge Free

Convert YAML to JSON instantly with our free online tool. No signup required.

Try YAMLforge Free