How do I rerun a successful azure devops YAML pipeline stage, and any stages that follow?

Viewed 6017

Stages A->B->C->D.

C failed with an error that implicates a problem in stage B's output, even though it succeeded. As a failed stage I can rerun C, and D will run if it succeeds (in this instance it still fails). I can rerun B, it succeeds again, but C and D are then "skipped" and I can't find a way to (re)run them.

How do I rerun B such that C and D will follow on success?

2 Answers

I made a test using this build configuration:

stages:
- stage: Test
  jobs:
  - job: A
    steps:
    - bash: echo "A"

- stage: DeployUS1
  dependsOn: Test    # this stage runs after Test
  jobs:
  - job: A
    steps:
    - bash: echo "A"
    - powershell: Invoke-WebRequest -URI https://some-endpoint.free.beeceptor.com/my/api/some

- stage: DeployUS2
  dependsOn: Test    # this stage runs in parallel with DeployUS1, after Test
  jobs:
  - job: A
    steps:
    - bash: echo "A"

- stage: DeployEurope
  dependsOn:         # this stage runs after DeployUS1 and DeployUS2
  - DeployUS1
  - DeployUS2
  jobs:
  - job: A
    steps:
    - bash: echo "A"

I made stage DeployUS1 failing by returning 404 from https://some-endpoint.free.beeceptor.com/my/api/some, and thus:

enter image description here

When I fixed this by changing mock rules to return 200 and I reran failing jobs I got DeployUS1 and next stage DeployEurope executed:

enter image description here

This works as you expected and docs says:

You can now retry a pipeline stage when the execution fails. Any jobs that failed in the first attempt and those that depend transitively on those failed jobs are all re-attempted.

So if you observed different than this it may be caused by misssing dependency:

stages:
- stage: FunctionalTest
  jobs:
  - job:
    ...

- stage: AcceptanceTest
  dependsOn: []    # this removes the implicit dependency on previous stage and causes this to run in parallel
  jobs:
  - job:
    ...

I reran Test which passed and it triggered next stages:

enter image description here

When DeployUS1 and DeployUS2 finished DeployEurope started autmatically:

enter image description here

If you click on your stage box on the main pipeline window, you will see an up and down arrow. Click on this to expand the stage and then there is a button to re-run the stage. You could always grab the requests it sends (f12) if you need to do this programatically.enter image description here

Related