5
votes

I wanted to know if there is any way we can know the result of a previous step execution in a build pipeline in azure dev ops.

To explain my query in detail: Lets say in azure Devops i have a build pipeline with as around 10 steps which performs few tasks like prepare for build, Build the solution, syncing and few other things.

Now i wanted to know the status of certain step execution whether it is failed or succeeded in other words:

  1. STEP 1: Successful
  2. STEP 2: Successful
  3. STEP 3: Failed
  4. STEP 4: I want to know the status of STEP 3 execution whether it is failed or successful based upon that I want to execute STEP 4
  5. STEP 5: Should get executed similar to STEP 4 i.e.based on step execution result of STEP 3
  6. STEP 6: Should be executed
  7. STEP 7: Should be executed

So on so forth till STEP 10..

My issue is how to achieve this? How to make the execution of few steps to not get executed based upon previous step execution result and then rest others Should get executed.

Please note I have tried to put like Execute only if all previous tasks have been successful but still it does not work. It still executes step 4 and 5.

Also note that the STEP 7 has some custom condition associated to it which works fine . This note was only given to provide more context how my build pipeline tasks are defined or created.

Please help me resolving this issue or achieving this kind of behavior.

2

2 Answers

2
votes

you can have custom condition to only execute steps 3 and 4 if previous steps failed failed() (at least one of the previous steps) but all the other steps after would either all be skipped (if they expect all the steps to succeed) or will be all executed (if you set them to succeededOrFailed().

you cannot really be dynamic in this decision.

https://docs.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops&tabs=yaml

2
votes

You may be able to do what you are after without Stages and Jobs, but I think the case you are describing is a good candidate for multiple Jobs within your pipeline. Here is an example yaml pipeline that follows the logic in your question. The combination of the dependsOn: and condition: will help you build these types of dependency graphs in your pipeline.

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

jobs:
- job: Foo 
  displayName: (Steps 1-2)
  steps:
  - script: echo Hello, world!
    displayName: Number 1

  - script: echo Hello, world!
    displayName: Number 2

- job: Bar 
  displayName: (Step 3)
  dependsOn: Foo
  steps:
  - script: 0\0
    displayName: Number 3

- job: Qux 
  displayName: (Step 4-5)
  dependsOn: Bar
  condition: failed()
  steps:
  - script: echo Hello, world!
    displayName: Number 4

  - script: echo Hello, world!
    displayName: Number 5

- job: baz
  displayName: (Step 6+)
  dependsOn: Qux
  condition: always()
  steps:
  - script: echo Hello, world!
    displayName: Number 6

  - script: echo Hello, world!
    displayName: Number 7

failed flow success flow