in build variable to detect rerun of failed builds

Viewed 683

Is there an inbuilt pipeline or build variable to check if the run is actually a re-run of a job/stage.

I need to add this in condition as some of the steps needs to be skipped based on this variable.

- conditions: rerun()

enter image description here

2 Answers

Yes, there are variables regarding this:

System.JobAttempt - Set to 1 the first time this job is attempted, and increments every time the job is retried.

System.StageAttempt - Set to 1 the first time this stage is attempted, and increments every time the job is retried.

You can find the full variable list here.

You can use the predefinded variables System.JobAttempt or System.StageAttempt to determine if it is a re-run of a job/stage.

To skip a step if it is a re-run of a job/stage, you can set the condtion as below:

condition: eq(variables['System.JobAttempt'], '1')

Related