Example 1
In this example:
Step B is triggered only if step A succeeds (default behavior), and step C is triggered only if step A is in failed, error, or timeout status.
Step B does not need any special configuration as the default behavior is to trigger a dependent step if the previous step succeeds.
Step A also does not need any special configuration since the step itself does not decide the downstream workflow path.
YAML
- name: demo_conditional steps: - name: step_A type: Bash configuration: inputResources: - name: script_conditional execution: onExecute: - echo "Executing step_A" - printenv - name: step_B type: Bash configuration: inputSteps: - name: step_A execution: onExecute: - echo "Executing step_B" - printenv - name: step_C type: Bash configuration: inputSteps: - name: step_A status: - failure - error - timeout execution: onExecute: - echo "Executing step_C" - printenv
Example 2
In this example, Step S is triggered if Step Q succeeds and Step R fails. However, if both Step Q and Step R succeed or fail during the run, Step S is not triggered and it is skipped.
YAML
- name: step_S type: Bash configuration: inputSteps: - name: step_Q status: - success - name: step_R status: - failure execution: onExecute: - echo "Executing step_S" - printenv
Example 3
In this example, Step O is triggered if Step M succeeds and Step N fails. However, since Step N is not part of the current run, Step O is triggered when Step M succeeds and Step N's status is ignored.
YAML
- name: step_O type: Bash configuration: inputSteps: - name: step_M status: - success - name: step_N status: - failure execution: onExecute: - echo "Executing step_O" - printenv
Example 4 - Using Environment Variable
The step_<inputStepName>_statusName
, which is an environment variable that is automatically made available at runtime, can be used in conjunction with conditional workflows. This step_<inputStepName>_statusName
environment variable is useful for fetching the status of any input step, especially when working with Jenkins.
YAML
resources: - name: script_gh type: GitRepo configuration: path: jfrog/sample-script gitProvider: myGithub branches: include: ^{{gitBranch}}$ pipelines: - name: simple_jenkins_demo steps: - name: jenkins type: Jenkins configuration: inputResources: - name: script_gh jenkinsJobName: testPipeline integrations: - name: myJenkins - name: step_A type: Bash configuration: inputSteps: - name: jenkins status: - failure - error - timeout execution: onExecute: - echo "Executing step_A" - if [ $step_jenkins_statusName == "failure" ]; then echo "Do something"; fi - if [ $step_jenkins_statusName == "error" ]; then echo "Do something else"; fi - name: simple_conditional_B type: Bash configuration: inputSteps: - name: jenkins status: - failure - error execution: onExecute: - echo "Executing simple_conditional_B" - printenv