Skip to content

Migrate bk job retry from GraphQL to REST#853

Open
jeremybumsted wants to merge 2 commits into
mainfrom
jb/job-retry-via-rest
Open

Migrate bk job retry from GraphQL to REST#853
jeremybumsted wants to merge 2 commits into
mainfrom
jb/job-retry-via-rest

Conversation

@jeremybumsted
Copy link
Copy Markdown

@jeremybumsted jeremybumsted commented Jun 5, 2026

Description

bk job retry was one of the last job commands using the GraphQL API — it
predates the pipeline/build resolver pattern and was copied from job unblock in #387.

This migrates it to the REST API using the organization-level job route added
in buildkite/buildkite#29824 (PUT /v2/organizations/:org/jobs/:job_id/retry) — the same API surface #833
adopted for bk job log, bk job reprioritize, and bk job unblock. Job
UUIDs are globally unique, so the selected organization plus the UUID is all
the context needed.

Why REST: works with standard token scopes (no GraphQL-enabled token
required), and keeps job commands on one consistent pattern.

An earlier revision of this PR used the build-scoped retry endpoint, which
required resolving a pipeline and build (-p/-b flags) and would have
broken bk job retry <uuid> outside a configured repository. Review caught
this — the org-level route avoids it entirely.

No behavior change: bk job retry <uuid> works with just a job UUID and
a selected organization, from anywhere — same as the GraphQL version it
replaces, and same as the other job commands after #833.

Changes

  • cmd/job/retry.go: rewritten to mirror reprioritize.go — requires a
    selected organization, calls the org-level retry route by job UUID
  • cmd/job/rest.go: adds a retryJob helper alongside the existing
    getJobLog/reprioritizeJob/unblockJob org-route helpers from fix: Use organization job routes #833
  • cmd/job/retry_test.go: asserts method, org-level path, and empty
    request body, matching the fix: Use organization job routes #833 test style
  • Removes cmd/job/graphql/retry.graphql and its generated code
    (internal/graphql/generated.go, −97 lines)
  • Incidentally removes the nil-payload crash guard — REST errors (e.g.
    retrying a job from a canceled build) now surface cleanly via the API error

New help output:

  Usage: bk job retry <job-id>

  Retry a job.

  Use this command to retry build jobs.

  Examples:

      # Retry a job by UUID
      $ bk job retry 0190046e-e199-453b-a302-a21a4d649d31

  Arguments:
    <job-id>    Job UUID to retry

  Flags:
    -h, --help        Show context-sensitive help.
    -y, --yes         Skip all confirmation prompts
        --no-input    Disable all interactive prompts
    -q, --quiet       Suppress progress output
        --no-pager    Disable pager for text output
        --debug       Enable debug output for REST API calls

Testing

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

Additional checks run:

  • golangci-lint run — 0 issues
  • mise run vulncheck — clean
  • mise run generate — no drift; generated.go matches codegen exactly

Notes

Disclosures / Credits

Claude Code (Opus 4.8) wrote this change end-to-end — exploration, planning,
implementation, and this PR description — with me reviewing and directing.

@jeremybumsted jeremybumsted requested review from a team as code owners June 5, 2026 21:36
@catkins
Copy link
Copy Markdown
Contributor

catkins commented Jun 5, 2026

change: bk job retry no longer works with zero context from outside a configured repository — pass -p/-b explicitly, like other job commands. Without -b, the job is assumed to be in the latest build on the current branch.

If it uses the org/<slug>/jobs/<uuid> route is that true?

Comment thread cmd/job/retry.go Outdated
type RetryCmd struct {
JobID string `arg:"" help:"Job UUID to retry"`
JobID string `arg:"" help:"Job UUID to retry"`
Pipeline string `help:"The pipeline to use. This can be a {pipeline slug} or in the format {org slug}/{pipeline slug}" short:"p"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a breaking change that requires Pipeline and Build number for this command? We added new APIs recently that we used for #833 can we lean on them?

Copy link
Copy Markdown
Author

@jeremybumsted jeremybumsted Jun 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lox Yeah, this would be a breaking change - intent was to use the APIs added in #833 but this branch was cut from an old old commit from main somehow and didn't have the changes. This is fixed now 🤦

updated PR description as well.

Copy link
Copy Markdown
Author

@jeremybumsted jeremybumsted Jun 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@catkins I think ☝️ addresses your comment, shouldn't need org/<slug>/jobs/<uuid> and I've since updated to remove that note

  Retries now go through the REST API using the same pipeline/build
  resolution as `bk job log` and `bk job reprioritize`: pipeline comes
  from the `-p` flag, configured pipeline, or the current git repository;
  build comes from the `-b` flag or the most recent build on the current
  branch.

  Why: the GraphQL path required a GraphQL-enabled token and was the odd
  one out among job commands — it predates the resolver pattern (it was
  copied from `job unblock` in #387). REST works with standard token
  scopes and keeps one consistent code path.

  Behavior change: `bk job retry <uuid>` no longer works with zero
  context from outside a configured repository — pass `-p` and `-b`
  explicitly, like other job commands. Without `-b`, the job is assumed
  to be in the latest build on the current branch.

  Also removes the retry GraphQL operation and its generated code; this
  incidentally fixes the nil-payload crash path previously guarded in
  retry.go (REST errors now surface cleanly).
   Use PUT /v2/organizations/:org/jobs/:job_id/retry (added in
   buildkite/buildkite#29824, adopted for other job commands in #833)
   instead of the build-scoped retry endpoint. This keeps `bk job retry
   <uuid>` working with only a job UUID and a selected organization — no
   pipeline or build context, no -p/-b flags, and no behavior change from
   the GraphQL version it replaces.
@jeremybumsted jeremybumsted force-pushed the jb/job-retry-via-rest branch from 8997fa0 to e6ba94c Compare June 5, 2026 22:12
@jeremybumsted jeremybumsted requested a review from lox June 5, 2026 22:16
Copy link
Copy Markdown
Contributor

@mcncl mcncl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YEET

Copy link
Copy Markdown
Contributor

@catkins catkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 excellent, thanks @jeremybumsted 🚀

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.

4 participants