-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CT-3142] [Feature] Make the current git branch (if any) available in the dbt Jinja context #8690
Comments
Thanks @b-per! There's been previous discussion about this: The most recent comment (from February) has the exact same request & use case, and I think I buy it. When you have multiple developers working on a single "feature" over the course of a few weeks, you may want them to:
What are the risks?dbt <> git interaction. dbt doesn't install git as a Python package dependency; it just uses the Partial parsing. I think this could have some wacky interactions with partial parsing. If you change your git branch, and you use the
|
I am a bit stuck on the partial parsing side of things but the rest (feature and testing) should be OK. I have also added a Thinking about it now, would we want to add this info in |
I'm commenting here since I was tagged on the PR. The big question I have from reading this issue is:
A few other considerations from an engineer's perspective (more for @jtcohen6):
And one more thing: can we experiment with using Dulwich in the PR? From the homepage:
This might be a way to mitigate the I'm excited to see where this discussion goes and what solution we come up with! |
My personal takes:
|
Hi There, |
Hi I'm here from searching for "dbt run set target to current git branch". Looks like there isn't a native way to do this interactively. In github actions CICD the pull step is going to select a branch and that will be accessible as a variable for dbt commands, so yeah my use-case is also REPL development workflow. Here's how I solve it with the just.systems taskrunner: I have a just environment that computes the current git branch name, which also match the names of my targets. # ./justfile
set positional-arguments := true
git_branch := `git symbolic-ref --short HEAD`
# select dev branch if not on main or stable (ie feature branches, etc)
branch := if (git_branch) == "main" { "main" } else if (git_branch) == "stable" { "stable" } else { "dev" }
current_git_commit := `git rev-parse HEAD | cut -c 1-8`
# just --list
_default:
@just --list --unsorted
# dbt run --target <git branch name is inserted here> <the rest of your command>
run *args:
dbt run --target {{branch}} "$@" The # currently 'dev' branch
just run
# dbt run --target dev "$@" |
@mahiki I considered using CI/CD, but there's a gap left in the workflow with that route. Developers / Analytic Engineers, they might be running their dbt project locally prior to a commit--to make sure it all runs at the very least. When they do so, the idea is that a schema is automatically created based on the git branch (e.g., Asking for my own curiosity; do you only deploy to the development branch of your analytical infrastructure via CI/CD, or can your engineers write directly to it? Edit: Maybe one approach that gets both benefits: Engineers get more static "user driven branches" in the dev branch of the analytical infrastructure (e.g., |
Is this your first time submitting a feature request?
Describe the feature
I would like to be able to access the current git branch name from the dbt context in order to be able to run some Jinja code depending on its value.
If we had
current_branch
available as a Jinja variable, we could potentially generate models in schemas/database (by adding some logic ingenerate_schema_name()
) that depend on this branch name.This could be useful for longer living branch where multiple developers will work on the same feature.
We would need to handle the case where dbt is run on code that is not a git repo/branch and maybe return an empty value then.
Describe alternatives you've considered
People could potentially define a
var
indbt_project.yml
to hard code what branch they are on. This variable would then have the same value as the current branch but the drawbacks are that:var
is defined as each branch would define its own valueWho will this benefit?
Are you interested in contributing this feature?
Yes!
Anything else?
No response
The text was updated successfully, but these errors were encountered: