Go client library for the Buildkite Stacks API. This package enables custom stack implementations to communicate with Buildkite's agent infrastructure, handling job scheduling, lifecycle management, and stack registration.
go get github.com/buildkite/stacksapiRequires a Buildkite Cluster Token (not a REST or GraphQL API token, or an unclustered Agent Registration Token). The token is passed to NewClient().
import "github.com/buildkite/stacksapi"
client, err := stacksapi.NewClient(
os.Getenv("BUILDKITE_CLUSTER_TOKEN"),
stacksapi.WithLogger(logger),
)WithLogger(logger *slog.Logger)- Configure structured logging. To integrate with non-slogloggers, we recommend using log adapters likeslog-zap,slog-zerologand friends.WithBaseURL(url *url.URL)- Override the default API endpointWithHTTPClient(client *http.Client)- Use a custom HTTP clientWithRetrierOptions(...roko.RetrierOpt)- Configure client-wide retry behavior. The default retry behaviour is an exponential backoff with jitter, retrying on 429 and 5xx responses. Retry behaviour can also be customized per-request usingWithRetrierandWithNoRetryrequest options.LogHTTPPayloads()- Enable request/response payload logging (may log sensitive data)PrependToUserAgent(prefix string)- Customize the User-Agent header. Note that when using this library, the user agent will always end withstacksapi v$SOME_VERSION
stack, _, err := client.RegisterStack(ctx, stacksapi.RegisterStackRequest{
Key: "my-stack",
Type: stacksapi.StackTypeCustom,
QueueKey: stacksapi.DefaultQueue,
Metadata: map[string]string{"version": "1.0"},
})jobs, _, err := client.ScheduledJobs(ctx, stacksapi.ScheduledJobsRequest{
StackKey: "my-stack",
})job, _, err := client.GetJob(ctx, stacksapi.GetJobRequest{
StackKey: "my-stack",
JobUUID: jobUUID,
})_, err = client.FinishJob(ctx, stacksapi.FinishJobRequest{
StackKey: "my-stack",
JobUUID: jobUUID,
ExitStatus: 0,
Detail: "Job completed successfully",
})_, err = client.DeregisterStack(ctx, "my-stack")Per-request options can be passed to any API method:
WithRetrier(retrier *roko.Retrier)- Override the default retry behaviorWithNoRetry()- Disable retries for the request
StackTypeCustom- For third-party stack implementations (recommended)StackTypeKubernetes- Reserved for first-partyagent-stack-k8sStackTypeElastic- Reserved for first-partyelastic-stack-for-aws
See example/main.go for a complete working example.
See LICENSE.txt.