Skip to content
Latchkey

How to Run dbt in CI

dbt in CI is mostly about installing the correct adapter and feeding warehouse credentials through environment variables, not the dbt core package.

You install dbt-core plus an adapter (dbt-postgres, dbt-snowflake, dbt-bigquery). CI then needs a profiles.yml that reads credentials from env, and a reachable warehouse for build/test.

Why it fails in CI

  • Only dbt-core is installed, not the warehouse adapter → "Could not find adapter".
  • profiles.yml hardcodes secrets or is missing → connection/auth errors.
  • dbt deps packages were not installed before dbt build.

Install and run it reliably

Install the adapter, point dbt at a profiles.yml that reads env vars, run deps, then build. Keep credentials in CI secrets.

Terminal
pip install dbt-core dbt-postgres   # swap adapter as needed

export DBT_HOST=... DBT_USER=... DBT_PASSWORD=...   # from CI secrets

dbt deps
dbt build --profiles-dir ./ci

Cache & speed

Cache ~/.cache/pip for the adapter and the dbt packages directory (dbt_packages) so dbt deps is not re-fetched. Use a warehouse service container for Postgres-based projects.

.github/workflows/ci.yml
- uses: actions/cache@v4
  with:
    path: ~/.cache/pip
    key: pip-${{ runner.os }}-${{ hashFiles('**/requirements*.txt') }}

Common errors

  • Could not find adapter type postgres → install dbt-postgres (or your adapter).
  • Credentials in profile ... could not be parsed → use env_var() and provide the env in CI.
  • Compilation Error ... depends on a package → run dbt deps before build.

Key takeaways

  • Install both dbt-core and the warehouse adapter.
  • Read warehouse credentials from env via env_var() in profiles.yml.
  • Run dbt deps before dbt build.

Related guides

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