Skip to content
Latchkey

How to Use dbt Tests as a CI Quality Gate

dbt test runs schema and data tests and exits non-zero on failure, making them a natural CI gate.

Declare generic tests in your schema YAML, then run dbt test in CI so violations fail the build like any other check.

Steps

  • Add not_null, unique, and relationships tests in schema.yml.
  • Run dbt test --target ci after building models.
  • Use --store-failures to persist failing rows for inspection.

schema.yml

models/schema.yml
models:
  - name: fct_orders
    columns:
      - name: order_id
        tests:
          - not_null
          - unique
      - name: customer_id
        tests:
          - not_null
          - relationships:
              to: ref('dim_customers')
              field: customer_id

Workflow

.github/workflows/ci.yml
steps:
  - run: dbt run --target ci
  - run: dbt test --target ci --store-failures

Gotchas

  • Set a test severity: warn for checks you want reported but not blocking.
  • --store-failures writes failing rows to a schema so you can query what broke.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →