Detect Rerun of a job

Is there a way to detect if the job has started the result of a rerun ?

You could probably use these environment variables:

  • CIRCLE_WORKFLOW_ID
  • CIRCLE_WORKFLOW_WORKSPACE_ID

If you check the “Preparing environment variables” step, you can see that the values of these variables are the same when the job runs first. When you rerun, workspace id stays the same, but the workflow id changes. An example from my test build

First run

CIRCLE_WORKFLOW_ID=ab3435ca-de56-4081-9a52-448215b46c9a
CIRCLE_WORKFLOW_WORKSPACE_ID=ab3435ca-de56-4081-9a52-448215b46c9a

Second run

CIRCLE_WORKFLOW_ID=62ca5e84-dbae-4341-bb99-6006962bf956
CIRCLE_WORKFLOW_WORKSPACE_ID=ab3435ca-de56-4081-9a52-448215b46c9a
1 Like