take precedence over pipeline-level defined hooks.To set up the local environment used below, follow the recommendations from the Project templates.

In steps/alerts/notify_on.py, you will find a step to notify the user about success and a function used to notify the user about step failure using the Alerter from the active stack.

We use @step for success notification to only notify the user about a fully successful pipeline run and not about every successful step.

In pipelines/training.py, you can find the usage of a notification step and a function. We will attach a notify_on_failure function directly to the pipeline definition like this:

from zenml import pipeline

@pipeline(

...

on_failure=notify_on_failure,

...

At the very end of the training pipeline, we will execute the notify_on_success step, but only after all other steps have finished - we control it with after statement as follows:

...

last_step_name = "promote_metric_compare_promoter"

notify_on_success(after=[last_step_name])

...

Accessing step information inside a hook

Similar as for regular ZenML steps, you can use the StepContext to access information about the current pipeline run or step inside your hook function:

from zenml import step, get_step_context

def on_failure(exception: BaseException):

context = get_step_context()

print(context.step_run.name)  # Output will be `my_step`

print(context.step_run.config.parameters)  # Print parameters of the step

print(type(exception))  # Of type value error

print("Step failed!")

@step(on_failure=on_failure)

def my_step(some_parameter: int = 1)

raise ValueError("My exception")

To set up the local environment used below, follow the recommendations from the Project templates.

In steps/alerts/notify_on.py, you will find a step to notify the user about success and a function used to notify the user about step failure using the Alerter from the active stack.