Skip to content

Cancel jobs via the REST job cancel endpoint - #1034

Merged
mitchbne merged 4 commits into
mainfrom
job-cancel-rest
Oct 12, 2026
Merged

mitchbne merged 4 commits into
mainfrom
job-cancel-rest

Conversation

@mitchbne

@mitchbne mitchbne commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

Description

bk job cancel now uses the new REST endpoint PUT /v2/organizations/{org}/jobs/{job}/cancel instead of the JobTypeCommandCancel GraphQL mutation. It still cancels only the given job; other jobs in the build keep running (bk build cancel cancels the whole build).

The call uses JobsService.CancelJobByOrg from go-buildkite v5.22.0, which this PR bumps to.

A running job returns canceling, so the command prints Job canceling: <url> in that case and Job canceled: <url> otherwise. The job stays canceling until its agent stops it, or until Buildkite finishes the cancellation itself: when the agent is lost (no heartbeat for 3 minutes), when it's force-canceled, or after an hour in canceling. API errors (e.g. 422 "You can only cancel jobs that have started") are surfaced unchanged. The confirmation prompt, --yes, --no-input, and --web behave as before.

Context

Testing

  • Tests have run locally (with go test ./...)
  • Code is formatted (with go fmt ./...)

Deployment

Release order (per Mitch): REST API ships → go-buildkite release → this PR → CLI release → skills.

  1. ✅ buildkite/buildkite#35937 is deployed to production (https://buildkite.com/buildkite/deploy/builds/27312).
  2. ✅ Add JobsService.CancelJob and CancelJobByOrg go-buildkite#395 (JobsService.CancelJobByOrg) is released in v5.22.0 (tag v5.22.0 → bb77c7d), and this PR depends on that exact version.
  3. Merge, and cut a CLI release (next after v3.61.1). Teach agents to cancel one job without canceling the build skills#50 should reference that CLI version.

Rollback

Revert this PR to restore the GraphQL mutation. No data or config changes.

@buildsworth-bk approve up to L2

bk job cancel now calls PUT /v2/organizations/{org}/jobs/{job}/cancel
instead of the JobTypeCommandCancel GraphQL mutation. It still cancels
only the given job, keeps the confirmation prompt and --web flag, and
reports running jobs as canceling until their agent stops them.

Amp-Thread-ID: https://ampcode.com/threads/T-01a12dc6-687b-720e-a303-e67227202fa9
Co-authored-by: Amp <[email protected]>

Copy link
Copy Markdown
Member Author

@buildsworth-bk review

buildsworth-bk-app[bot]
buildsworth-bk-app Bot previously approved these changes Oct 12, 2026
go-buildkite v5.22.0 adds JobsService.CancelJobByOrg for the REST job
cancel endpoint, so bk job cancel now calls it instead of a local
request helper. Behaviour and output are unchanged.

Amp-Thread-ID: https://ampcode.com/threads/T-01a12dc6-687b-720e-a303-e67227202fa9
Co-authored-by: Amp <[email protected]>

Copy link
Copy Markdown
Member Author

@buildsworth-bk review

buildsworth-bk-app[bot]
buildsworth-bk-app Bot previously approved these changes Oct 12, 2026
@buildsworth-bk-app
buildsworth-bk-app Bot dismissed their stale review October 12, 2026 06:57

Superseded by a newer Buildsworth review.

@mitchbne
mitchbne marked this pull request as ready for review October 12, 2026 06:58
@mitchbne
mitchbne requested review from a team as code owners October 12, 2026 06:58
buildsworth-bk-app[bot]
buildsworth-bk-app Bot previously approved these changes Oct 12, 2026
@buildsworth-bk-app
buildsworth-bk-app Bot dismissed their stale review October 12, 2026 07:01

Superseded by a newer Buildsworth review.

A canceling job doesn't only wait for its agent: Buildkite also finishes
the cancellation when the agent is lost, when it's force-canceled, or
after an hour in canceling. Say so in the help text and comment.

Amp-Thread-ID: https://ampcode.com/threads/T-92eb1268-cb9f-42e4-a2d9-09d72ca6c99d
Co-authored-by: Amp <[email protected]>
buildsworth-bk-app[bot]
buildsworth-bk-app Bot previously approved these changes Oct 12, 2026
@buildsworth-bk-app
buildsworth-bk-app Bot dismissed their stale review October 12, 2026 07:10

Superseded by a newer Buildsworth review.

@buildsworth-bk-app
buildsworth-bk-app Bot dismissed their stale review October 12, 2026 07:26

Superseded by a newer Buildsworth review.

@mitchbne
mitchbne merged commit 95e686d into main Oct 12, 2026
2 checks passed
@mitchbne
mitchbne deleted the job-cancel-rest branch October 12, 2026 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants