CI/CD with BigQuery automates testing and deployment of SQL, datasets, and views through version-controlled pipelines.
Automating testing and deployment prevents ad-hoc scripts, enforces review, and lets engineers roll back safely. Pipelines validate SQL, run unit tests against temporary datasets, and promote artifacts to production when checks pass.
GitHub Actions, GitLab CI, and Cloud Build provide managed runners that can call the bq CLI and Terraform.Combine them with dbt Core for model tests or with sqlfluff for linting.
Keep SQL files in /sql, dbt models in /models, and Terraform in /infra. Use one folder per logical area (e.g., orders, customers).Store test data as CSV in /tests/fixtures for deterministic unit tests.
Use a .github/workflows/bigquery.yml
file that installs the Cloud SDK, authenticates with a service account, lints SQL, executes unit tests on a sandbox dataset, and deploys to prod on the main branch.
The google-github-actions/setup-gcloud
action installs the SDK and bq CLI so subsequent steps can run BigQuery commands.
Store a JSON key as a GitHub secret.Export GOOGLE_APPLICATION_CREDENTIALS
to allow Terraform, dbt, and raw bq commands to run.
Run sqlfluff lint sql/ --dialect bigquery
and dbt's dbt test
against a temporary dataset ci_$(date +%s)
.Fail the job on any error.
On push to main
or a tagged release, run terraform apply --auto-approve
(or dbt run
) to create views, tables, or authorized routines in the prod dataset.
Create staging datasets such as ci_customers
, insert fixture rows for Customers
, Orders
, Products
, and OrderItems
, then run assertions verifying record counts or totals.
Assign least-privilege service accounts, cache the Cloud SDK layer, clean up temp datasets at job end, and publish coverage metrics to keep pipelines fast and secure.
Use Terraform state rollbacks or dbt full-refresh to revert schema changes.Snapshot production datasets nightly so you can restore data quickly.
.
Yes. Cloud Build natively authenticates to BigQuery and can execute bash, Terraform, or dbt steps—reducing external dependencies.
Materialize models as view
in CI, limit fixture row counts, and cache the Python environment between jobs.
Temporary datasets and <1 TB processed per month remain free in the BigQuery sandbox, making small CI runs cost-effective.