Skip to main content

How to Rerun a Workflow via the API When the UI Shows a Stale State

Rerun a workflow via the API

Overview

Sometimes a workflow or job gets stuck in a stale or stalled state in the CircleCI web app. The UI may show the workflow as still running, or it may not offer a Rerun option. When that happens, you can still rerun the workflow through the CircleCI API. The API doesn't need the UI to show the workflow as completed first.

Before you begin

  • You need the workflow ID. It's the UUID in the workflow URL: https://app.circleci.com/pipelines/<vcs>/<org>/<repo>/<pipeline-number>/workflows/<WORKFLOW_ID>

Option 1: Rerun with the v3 API

Send a POST request to the v3 rerun endpoint:

POST /api/v3/workflows/{id}/rerun

See the v3 API reference for the full request details.

Option 2: Rerun with the v2 API

If the v3 API doesn't work for you, use the v2 rerunWorkflow endpoint:

curl --request POST \

--header "Circle-Token: ${CIRCLE_TOKEN}" \

--header "Content-Type: application/json" \

--data '{"enable_ssh": false, "from_failed": false}'

A successful request returns HTTP 202 and the ID of the new workflow:

{ "workflow_id": "0e53027b-521a-4c40-9042-47e72b3c63a3" }

Request body options

Parameter

Description

from_failed

Set to true to rerun only from the failed job. Can't be combined with jobs.

jobs

A list of job IDs to rerun. Can't be combined with from_failed.

enable_ssh

Enables SSH for the rerun job. Requires jobs, so it can't be combined with from_failed.

Tip: In a multi-line curl command, put a backslash (\) at the end of every line except the last. A missing backslash means the request body is dropped, and the whole workflow reruns from the start.

If you see "Workflow must be in a terminal state to be rerun"

If either endpoint returns a message like this:

Workflow must be in a terminal state to be rerun

the API sees the workflow as still in progress.

  1. If the workflow is stalled and you're sure nothing is actually running, contact CircleCI Support. Include a link to the workflow or build you're trying to rerun. The workflow may have been missed by our engineering team's cleanup of stalled builds, and we'll investigate.

Additional Resources

Did this answer your question?