Skip to main content

Continuous integration in dbt Cloud

To implement a continuous integration (CI) workflow in dbt Cloud, you can set up automation that tests code changes by running CI jobs before merging to production. dbt Cloud tracks the state of what’s running in your production environment so, when you run a CI job, only the modified data assets in your pull request (PR) and their downstream dependencies are built and tested in a staging schema. You can also view the status of the CI checks (tests) directly from within the PR; this information is posted to your Git provider as soon as a CI job completes. Additionally, you can enable settings in your Git provider that allow PRs only with successful CI checks be approved for merging.

Workflow of continuous integration in dbt CloudWorkflow of continuous integration in dbt Cloud

Using CI helps:

  • Provide increased confidence and assurances that project changes will work as expected in production.
  • Reduce the time it takes to push code changes to production, through build and test automation, leading to better business outcomes.
  • Allow organizations to make code changes in a standardized and governed way that ensure code quality without sacrificing speed.

How CI works

When you set up CI jobs, dbt Cloud listens for notification from your Git provider indicating that a new PR has been opened or updated with new commits. When dbt Cloud receives one of these notifications, it enqueues a new run of the CI job.

dbt Cloud builds and tests models, semantic models, metrics, and saved queries affected by the code change in a temporary schema, unique to the PR. This process ensures that the code builds without error and that it matches the expectations as defined by the project's dbt tests. The unique schema name follows the naming convention dbt_cloud_pr_<job_id>_<pr_id> (for example, dbt_cloud_pr_1862_1704) and can be found in the run details for the given run, as shown in the following image:

Viewing the temporary schema name for a run triggered by a PRViewing the temporary schema name for a run triggered by a PR

When the CI run completes, you can view the run status directly from within the pull request. dbt Cloud updates the pull request in GitHub, GitLab, or Azure DevOps with a status message indicating the results of the run. The status message states whether the models and tests ran successfully or not.

dbt Cloud deletes the temporary schema from your data warehouse when you close or merge the pull request. If your project has schema customization using the generate_schema_name macro, dbt Cloud might not drop the temporary schema from your data warehouse. For more information, refer to Troubleshooting.

Differences between CI jobs and other deployment jobs

The dbt Cloud scheduler executes CI jobs differently from other deployment jobs in these important ways:

 Concurrent CI checks
 Smart cancellation of stale builds
 Run slot treatmentteamenterprise
 Compare changesbeta
0