Skip to content

Lifecycle-Hook

v3.3 and after

Introduction

A LifecycleHook triggers an action based on a conditional expression. It is configured either at the workflow-level or template-level, for instance as a function of the workflow.status or steps.status, respectively. A LifecycleHook executes during execution time and executes once.

In other words, a LifecycleHook functions like an exit handler with a conditional expression.

Workflow-level LifecycleHook: Executes the workflow when a configured expression is met.

Template-level Lifecycle-Hook: Executes the template when a configured expression is met.

Supported conditions

Unsupported conditions

  • outputs are not usable since LifecycleHook executes during execution time and outputs are not produced until the step is completed.

Notification use case

A LifecycleHook can be used to configure a notification depending on a workflow status change or template status change, like the example below:

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
 generateName: lifecycle-hook-
spec:
 entrypoint: main
 hooks:
   exit:
     template: http
   running:
     expression: workflow.status == "Running"
     template: http
 templates:
   - name: main
     steps:
       - - name: step1
           template: heads

   - name: heads
     container:
       image: alpine:3.6
       command: [sh, -c]
       args: ["echo \"it was heads\""]

   - name: http
     http:
       url: http://dummy.restapiexample.com/api/v1/employees

Comments

Back to top