So I’m using dbt core with snowflake data warehouse. I’m using dbt in some Kubeflow components in a pipeline… and when the components run, I want to be able to see which dbt command it has been invoked to run this component. I know I can show the input parameters for a pipeline… but my main question how can I print what invocation_command was triggered for dbt. I have read many documentation webpages and I found this invocation_command variable that has the value, but I could not find how I can get its value and then print it in the logs that dbt usually prints.
Thanks in advance
What I’ve already tried
I have tried dbt --debug run but then the log is too too long… I only want the regular logs, with the invocation_command value.
@Ruba_AT the invocation_command inside of the invocation_args dict is exposed by the Jinja context, so you need to access it from somewhere that can render Jinja.
In your case I would put it in an on-run-start hook in dbt_project.yml:
(dbt-prod) joel@Joel-Labes joel-sandbox % dbt run -s first_model
22:16:16 Running with dbt=1.7.0
22:16:17 Registered adapter: snowflake=1.7.0
22:16:17 Unable to do partial parsing because a project config has changed
Running command: dbt run -s first_model
Yes you’re right - Jinja is the templating language dbt uses, and its commands are enclosed in curly braces: {{ for templates and {% for commands. Jinja and macros | dbt Developer Hub
Can you paste your full dbt_project.yml file? Make sure you do it as a code block (inside of backticks) to preserve the spaces as yaml is a space-sensitive language
# Name your project! Project names should contain only lowercase characters and underscores.
name: 'my_project_dbt'
version: '1.0.0'
config-version: 2
# This setting configures which "profile" dbt uses for this project.
profile: 'data_project'
# These configurations specify where dbt should look for different types of files.
model-paths: ["models"]
analysis-paths: ["analyses"]
test-paths: ["tests"]
seed-paths: ["seeds"]
macro-paths: ["macros"]
snapshot-paths: ["snapshots"]
clean-targets: # directories to be removed by `dbt clean`
- "target"
- "dbt_packages"
models:
my_project_dbt:
+on-run-start:
- "{{ print('Running command: ' ~ invocation_args_dict['invocation_command']) }}"
+materialized: table
Try moving the on-run-start block to the root level (instead of indented under models) like this:
# Name your project! Project names should contain only lowercase characters and underscores.
name: 'my_project_dbt'
version: '1.0.0'
config-version: 2
# This setting configures which "profile" dbt uses for this project.
profile: 'data_project'
# These configurations specify where dbt should look for different types of files.
model-paths: ["models"]
analysis-paths: ["analyses"]
test-paths: ["tests"]
seed-paths: ["seeds"]
macro-paths: ["macros"]
snapshot-paths: ["snapshots"]
clean-targets: # directories to be removed by `dbt clean`
- "target"
- "dbt_packages"
on-run-start:
- "{{ print('Running command: ' ~ invocation_args_dict['invocation_command']) }}"
models:
my_project_dbt:
+materialized: table