Run your dbt Cloud production job on every merge to main
Every time a pull request merges into main, we kick off your dbt Cloud production job so your warehouse always reflects the exact code that just shipped.
Whenever a pull request is merged into the default branch (main) of my GitHub repository, run my dbt Cloud production deployment job so the warehouse rebuilds from exactly the code that just landed. This is a deterministic code workflow: one GitHub merge comes in, one dbt Cloud run goes out, with no branching logic.
Trigger on GitHub pull request webhooks. Only proceed when the pull request was actually merged into main: the event is a pull_request event whose action is closed, whose merged flag is true, and whose base branch is the repository's default branch (main). Ignore pull requests that were closed without merging, and ignore merges into any other branch, so the job only runs on genuine deployments to main.
When a qualifying merge fires, call the dbt Cloud Trigger Job Run operation to kick off the configured production job, using the dbt Cloud account id and the production job id. Pass a cause message that references the merged pull request number and the merged commit SHA, for example 'Deploy: merged PR #<number> at <commit sha>', so every run is traceable back to the change that triggered it.
Pin the run to the merged code by passing the merged commit SHA as the run's git_sha override (the pull request's merge commit SHA), and optionally set git_branch to main, so dbt Cloud builds exactly that commit rather than whatever happens to be latest on the branch. Trigger the run and finish; there is no follow-up polling or notification step.
What does this prompt do?
- Watches your GitHub repository and springs into action the moment a pull request is merged into your main branch.
- Automatically starts your dbt Cloud production deployment job so your data models rebuild from the exact code that just landed.
- Ignores pull requests that were closed without merging and merges into other branches, so the job only runs on real deployments to main.
- Records the pull request number and commit behind each run, so every deployment traces back to the change that triggered it.
What do I need to use this?
- A GitHub repository where your team merges pull requests into a main branch.
- A dbt Cloud account with a production deployment job already set up.
- Permission to connect both your GitHub repository and your dbt Cloud account to General Input.
How can I customize it?
- Point it at a different branch, like production or release, instead of main.
- Choose which dbt Cloud job runs, for example a full build versus a lighter refresh.
- Adjust the note attached to each run so it shows the pull request number and commit the way your team prefers.
FAQs
Will this run every time I close a pull request?
Does it build the exact code that was merged?
What if I merge into a branch other than main?
Do I need to write any code?
Can I use my existing dbt Cloud production job?
Related templates
When you merge a fix in GitHub, this agent checks the matching dead-letter queue, replays the failed messages, and reports back on the pull request and in Slack.
Every night, find the preview databases whose pull request closed days ago, delete only the ones that are safe, and report the savings in Slack.
Every weekday morning, surface the security checks nobody has reviewed yet, file them in the right repository, and post your team one clear summary.
When a pull request changes the database, we create a matching PlanetScale branch for reviewers and post its name right on the pull request.
The moment a Render deploy fails, get a Slack post naming the likely cause, the commit and author behind it, and the last deploy that worked.
Every month, turn the features that truly reached customers into a plain language release note draft in Notion, ready for a product manager to review.
Ship to production the moment code merges.
Connect GitHub and dbt Cloud once, and every merge to main kicks off your production build automatically.