Step Status Conditional Workflow
With thestatus
有条件的工作流,您可以配置一个步骤execute only if an input step’s status, during its current run, is satisfied. You can configure any number of statuses for a step.
steps: - name:type: configuration: inputSteps: - name: status: - - -
It is important to note that only the status of an input step in the current run is considered for conditional workflows. If a step is not part of the current run, it is always assumed that the condition for that input step is met.
Adding Conditional Workflow for Steps
To add a conditional workflow for a step:
- In the
inputSteps
section of a step, add thestatus
property. - Add any of these values:
success
failure
error
cancelled
skipped
unstable
timeout
Ensure that the values are in lowercase and use the same spelling as shown above. Any deviation from this will cause the pipeline source sync to fail.
Example: In this example:
- step_B has only one status:
success
- step_c has multiple statuses:
failure
,skipped
,cancelled
- name: step_A type: Bash configuration: inputSteps: - name: step_B status: - success - name: step_C status: - failure - skipped - cancelled
Viewing Run Logs
When you run a pipeline, in addition to the other logs, the logs for steps with conditional workflow provide information about the skipped steps.
To view these logs, go to thePipeline Run Logsview, click the skipped step to display the logs for the current run.
Examples
Example 1
In this example:
- 步骤B 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.
- 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.
- 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.
- name: step_O type: Bash configuration: inputSteps: - name: step_M status: - success - name: step_N status: - failure execution: onExecute: - echo "Executing step_O" - printenv
例4 -使用环境Variable
Thestep_
, which is an environment variable that is automatically made available at runtime, can be used in conjunction with conditional workflows. Thisstep_
environment variable is useful for fetching the status of any input step, especially when working with Jenkins.
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