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, andrelationshipstests inschema.yml. - Run
dbt test --target ciafter building models. - Use
--store-failuresto 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_idWorkflow
.github/workflows/ci.yml
steps:
- run: dbt run --target ci
- run: dbt test --target ci --store-failuresGotchas
- Set a test
severity: warnfor checks you want reported but not blocking. --store-failureswrites failing rows to a schema so you can query what broke.
Related guides
How to Run Great Expectations as a CI Quality GateAdd a Great Expectations checkpoint to CI so a pull request fails when data does not meet its expectation sui…
How to Run dbt build and Tests on Pull Requests in CIRun dbt build on every pull request in GitHub Actions so models compile, run, and pass their tests against a…