0
0
dbtdata~10 mins

dbt in CI/CD pipelines - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - dbt in CI/CD pipelines
Code Commit to Repo
CI Pipeline Triggered
Install dbt & Dependencies
Run dbt Commands
dbt run
Report Results
Deploy if OK
Done
This flow shows how a code commit triggers a CI pipeline that installs dbt, runs dbt commands, reports results, and deploys if tests pass.
Execution Sample
dbt
git push origin main
# triggers CI pipeline
pip install dbt
dbt run
dbt test
dbt docs generate
This code simulates pushing changes that trigger a CI pipeline which installs dbt and runs dbt commands.
Execution Table
StepActionCommand/CheckResultNext Step
1Code pushed to repogit push origin mainPush accepted, CI triggeredInstall dbt
2Install dbtpip install dbtdbt installed successfullyRun dbt run
3Run modelsdbt runModels compiled and runRun dbt test
4Run testsdbt testAll tests passedGenerate docs
5Generate docsdbt docs generateDocumentation createdReport results
6Report resultsCI logs outputSuccess reportedDeploy if tests pass
7DeployDeploy to productionDeployment doneDone
8EndPipeline completeCI/CD pipeline finished successfullyExit
💡 Pipeline ends after deployment and reporting success.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4After Step 5Final
dbt_installedFalseTrueTrueTrueTrueTrue
models_runFalseFalseTrueTrueTrueTrue
tests_passedFalseFalseFalseTrueTrueTrue
docs_generatedFalseFalseFalseFalseTrueTrue
deployment_doneFalseFalseFalseFalseFalseTrue
Key Moments - 3 Insights
Why do we run 'dbt test' after 'dbt run'?
Because 'dbt run' builds the models, and 'dbt test' checks if those models are correct. This order ensures tests run on the latest models, as shown in steps 3 and 4 in the execution_table.
What happens if tests fail during 'dbt test'?
The pipeline stops before deployment to avoid pushing bad changes. This is implied by the flow where deployment only happens after tests pass (step 4 to 7).
Why generate docs in the CI pipeline?
Generating docs (step 5) helps keep documentation updated automatically with the latest models, improving team communication and transparency.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the state of 'tests_passed' after step 4?
AFalse
BUnknown
CTrue
DNot applicable
💡 Hint
Check the variable_tracker row for 'tests_passed' after step 4.
At which step does the pipeline generate documentation?
AStep 5
BStep 4
CStep 3
DStep 6
💡 Hint
Look at the 'Action' column in the execution_table for 'Generate docs'.
If 'dbt test' fails, what happens next in the pipeline?
ADeployment proceeds anyway
BPipeline stops before deployment
CDocs are generated anyway
DTests are rerun automatically
💡 Hint
Refer to the key_moments explanation about test failure stopping deployment.
Concept Snapshot
dbt in CI/CD pipelines:
- Code push triggers CI pipeline
- Install dbt and dependencies
- Run 'dbt run' to build models
- Run 'dbt test' to validate models
- Generate docs with 'dbt docs generate'
- Deploy only if tests pass
- Automates safe, tested data model deployment
Full Transcript
When you push code to your repository, it triggers a CI pipeline. The pipeline first installs dbt and its dependencies. Then it runs 'dbt run' to build your data models. After that, it runs 'dbt test' to check if the models are correct. If all tests pass, it generates documentation using 'dbt docs generate'. Finally, if everything is successful, the pipeline deploys the changes to production. If tests fail, deployment stops to keep your data safe. This flow helps automate and secure your data transformations.