log results in on-run-end hook only when dbt run is executed.

The problem I’m having

Right now, we are logging metadata about the run using the on-run-end hook, the issue is that no matter what command is ran (dbt seed, dbt, snapshot) the on-run-end executes. Is there a way to add a condition so that the run only gets logged if it’s ‘dbt run’ and not snapshot, seed, or anything else?

current on-run-end command

on-run-end:
  - "{% if target.name == 'prod' %}{{ dbt_artifacts.upload_results(results) }}{% endif %}"

You could try using invocation_args_dict.which

Something like

on-run-end:
  - "{% if target.name == 'prod' and invocation_args_dict.which == 'run' %}{{ dbt_artifacts.upload_results(results) }}{% endif %}"
2 Likes

I’m curious if a similar behavior can be achieved using the execute variable :thinking: