github.com/oam-dev/kubevela@v1.9.11/docs/examples/workflow/app-with-if/README.md (about)

     1  # Steps with if
     2  
     3  Every step can specify a `if`, you can use the `if` to determine whether the step should be executed or not.
     4  
     5  ## Always
     6  
     7  If you want to execute the step no matter what, for example, send a notification after the component is deployed even it's failed, you can use the `if` with the value `always` like:
     8  
     9  ```yaml
    10  apiVersion: core.oam.dev/v1beta1
    11  kind: Application
    12  metadata:
    13    name: if-always-with-err
    14    namespace: default
    15  spec:
    16    components:
    17    - name: err-component
    18      type: k8s-objects
    19      properties:
    20        objects:
    21          - err: "error case"
    22    workflow:
    23      steps:
    24      - name: apply-err-comp
    25        type: apply-component
    26        properties:
    27          component: err-component
    28      - name: notification
    29        type: notification
    30        if: always
    31        properties:
    32          slack:
    33            url:
    34              value: <your slack webhook url>
    35            message:
    36              text: always
    37  ```
    38  
    39  ## Custom Judgement
    40  
    41  You can also write your own judgement logic to determine whether the step should be executed or not, note that the values of `if` will be executed as cue code. We support some built-in variables to use in `if`, they are:
    42  
    43  * `status`: in this value, you can get the status of the step for judgement like `status.<step-name>.phase == "succeeded"`, or you can use the simplify way `status.<step-name>.succeeded`.
    44  * `inputs`: in this value, you can get the inputs of the step for judgement like `inputs.<input-name> == "value"`.
    45  
    46  ### Status Example
    47  
    48  If you want to control the step by the status of another step, you can follow the example:
    49  
    50  ```yaml
    51  apiVersion: core.oam.dev/v1beta1
    52  kind: Application
    53  metadata:
    54    name: if-timeout
    55    namespace: default
    56  spec:
    57    components:
    58    - name: comp-custom-timeout
    59      type: webservice
    60      properties:
    61        image: crccheck/hello-world
    62        port: 8000
    63    workflow:
    64      steps:
    65      - name: suspend
    66        timeout: 5s
    67        type: suspend
    68      - name: suspend2
    69        # or `status.suspend.reason == "Timeout"`
    70        if: status.suspend.timeout
    71        type: suspend
    72        timeout: 5s
    73      - name: notification-1
    74        type: notification
    75        if: suspend.timeout
    76        properties:
    77          slack:
    78            url:
    79              value: <your slack webhook url>
    80            message:
    81              text: suspend is timeout
    82      - name: notification-2
    83        type: notification
    84        if: status["notification-1"].succeeded
    85        properties:
    86          slack:
    87            url:
    88              value: <your slack webhook url>
    89            message:
    90              text: notification-1 is succeeded
    91  ```
    92  
    93  ### Inputs example
    94  
    95  If you want to control the step by the inputs of another step, you can follow the example:
    96  
    97  ```yaml
    98  apiVersion: core.oam.dev/v1beta1
    99  kind: Application
   100  metadata:
   101    name: if-input
   102    namespace: default
   103  spec:
   104    components:
   105    - name: comp-custom-timeout
   106      type: webservice
   107      properties:
   108        image: crccheck/hello-world
   109        port: 8000
   110    workflow:
   111      steps:
   112      - name: suspend
   113        type: suspend
   114        timeout: 5s
   115        outputs:
   116          - name: test
   117            valueFrom: context.name + " message"
   118      - name: notification
   119        type: notification
   120        inputs:
   121          - from: test
   122            parameterKey: slack.message.text
   123        if: inputs.test == "if-input message"
   124        properties:
   125          slack:
   126            url:
   127              value: <your slack webhook url>
   128            message:
   129              text: from input
   130  ```