---
title: "Failing an Azure DevOps Pipeline Early with a Validation Stage"
description: "A small validation stage catches broken YAML, missing variables and lint errors before any deploy runs."
url: "https://nishantxrana.com/writing/azure-devops-validation-stage"
canonical: "https://nishantxrana.com/writing/azure-devops-validation-stage"
date: "2026-12-01T16:48:42Z"
tags: "azure, devops, cicd, pipelines"
discussion: "https://dev.to/nishantxrana/failing-an-azure-devops-pipeline-early-with-a-validation-stage-4hmi"
---

# Failing an Azure DevOps Pipeline Early with a Validation Stage

_A small validation stage catches broken YAML, missing variables and lint errors before any deploy runs._

Long pipelines that fail in the last stage waste time. A short validation stage at the top fails fast instead.

## The stage

```yaml
stages:
  - stage: Validate
    jobs:
      - job: checks
        pool: { vmImage: ubuntu-latest }
        steps:
          - script: |
              test -n "$(AppName)" || { echo "AppName is not set"; exit 1; }
            displayName: Required variables
          - script: npm ci && npm run lint
            displayName: Lint

  - stage: Deploy
    dependsOn: Validate
    condition: succeeded()
    jobs:
      - deployment: web
        environment: prod
        strategy:
          runOnce:
            deploy:
              steps:
                - script: echo "deploying"
```

## A tiny helper script

```ts
export function requireEnv(names: string[]) {
  const missing = names.filter((n) => !process.env[n])
  if (missing.length) throw new Error(`Missing: ${missing.join(', ')}`)
}
```

## What to put in Validate

1. Required variable checks
2. Lint and type-check
3. `helm template` / `terraform validate`
4. Unit tests that run in under a minute

Reference: <https://learn.microsoft.com/azure/devops/pipelines/process/stages>

Keep it fast: if Validate takes longer than a few minutes, move the slow parts later.

---

Canonical: https://nishantxrana.com/writing/azure-devops-validation-stage · Index for agents: https://nishantxrana.com/llms.txt · Contact: nishantxrana@gmail.com
