Rerun Workflow from Failed including some Succeeded

Hi,

I have a long running workflow that takes 1.5-2 hours and sometimes fails almost at its end on one of the jobs due to flaky tests. This job, say X has dependencies on jobs A and B.
When X fails the workflow, I can restart the workflow again and wait long hours to know the outcome but obviously I want to iterate faster and don’t want to wait too long.
CircleCI gives the ability to restart workflow from the failed jobs and so it will re-run X if I use this option. The problem is that X has a resource dependency on B because B creates kubernetes cluster or something. When the workflow completes (or fails), it cleans up all resources and so next time I re-run from failed, i.e. only X, there will be no resources that X depends on and it will fail.
I need to be able to re-run both B and X when X fails. The problem is that B succeeds and CircleCI will not re-run it if I choose to rerun from failed. Is there a way to restart only succeeding job B and failing job X without re-running the whole workflow?

Probably, the workflow should be re-engineered in some way so that resources creation for X is part of X but as I’m new to CircleCI, I’m wondering is there a more lightweight approach.

Thanks,
Misha

1 Like

Okay, this seems possible by using CicrleCI API - CircleCI API takes list of job IDs to rerun.

  1. Create a token CircleCI and set to some environment variable, say CIRCLE_TOKEN.

  2. On the website you see job numbers (e.g. 1183929) but you need to convert them to job IDs (e.g. e9d881a2-7677-4108-b577-902fe46d30ec).
    Run the following command and find there job ids for job numbers. Obviously, swap workflow id with yours.

curl --request GET \
  --url https://circleci.com/api/v2/workflow/059e129b-48a4-4330-a4f8-3196871b012e/job \
  --header "Circle-Token: $CIRCLE_TOKEN" | less
  1. Paste the job ids in the following command and run it to restart given jobs in your workflow.
curl -v --request POST \
  --url https://circleci.com/api/v2/workflow/059e129b-48a4-4330-a4f8-3196871b012e/rerun \
  --header "Circle-Token: $CIRCLE_TOKEN" \
  --header 'content-type: application/json' \
  --data '{"jobs":["e9d881a2-7677-4108-b577-902fe46d30ec","1ef6b29b-505d-4028-a61c-434a25e95ade"],"from_failed":false}'