Skip to content

Instantly share code, notes, and snippets.

@nils-s
Last active October 6, 2023 11:35
Show Gist options
  • Save nils-s/7d727675e554877e518c380872851c46 to your computer and use it in GitHub Desktop.
Save nils-s/7d727675e554877e518c380872851c46 to your computer and use it in GitHub Desktop.
GitHub pages deploy failure

Dealing with stuck GitHub Pages deployments

Problem

When publishing a GitHub page for a repo, the deploy action might fail with an HTTP-400 error:

Failed to create deployment (status: 400) with build version <build version hash>.
Responded with: Deployment request failed for <build version hash> due to in progress deployment.
Please cancel <deployment hash> first or wait for it to complete.

Solution

Based on a (now apparently defunct) community discussion thread. Another (still working) discussion of the same issue.

Step 1

List deployments for the repo:

curl -u "<username>:<password or API key>" -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/<username>/<reponame>/deployments

Find the one that where the attribute sha matches the <deployment hash> mentioned in the deploy action's error message.

Make a (mental) note of the url attribute of that deployment (needed in step 3).

Step 2 (Optional)

check the status of the deployment by opening the statuses_url, there's probably an "in progress" entry

Step 3

delete the offending deployment:

curl -u "<username>:<password or API key>" -H "Accept: application/vnd.github.v3+json" -X DELETE <deployment URL>

Step 4

maybe wait a minute or two, then re-start the "pages build and deployment" workflow

Remarks

  • according to a comment by @easrng, you might also need to cancel the pages deployment:

    curl -u "<username>:<password or API key>" -H "Accept: application/vnd.github.v3+json" -X POST https://api.github.com/repos/<username>/<reponame>/pages/deployments/<deployment hash>/cancel
  • for more info regarding the relevant ReST API endpoints, see the GitHub API documentation, e.g. regarding Deployments and Pages.

  • for API authentication, instead of the ... -u "<username>:<password or API key>" ... part, it is also possible to use ... -H "Authorization: Bearer <access token>" ..., using an access token with the required permissions (see API docs for required permissions). This is also the way shown in the examples in the API docs

@easrng
Copy link

easrng commented Apr 5, 2023

I also had to do this:

curl -u "<username>:<password or API key>" -H "Accept: application/vnd.github.v3+json" -X POST https://api.github.com/repos/<username>/<reponame>/pages/deployments/<deployment hash>/cancel

@nils-s
Copy link
Author

nils-s commented Apr 11, 2023

I also had to do this:

curl -u "<username>:<password or API key>" -H "Accept: application/vnd.github.v3+json" -X POST https://api.github.com/repos/<username>/<reponame>/pages/deployments/<deployment hash>/cancel

Thanks for the tip 👍

I've updated the Gist accordingly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment