Documentation
¶
Overview ¶
Package api provides an API client for the Buildkite Pipelines API.
It is intended for internal use by buildkite-agent only.
Index ¶
- Constants
- Variables
- func BreakOnNonRetryable(r *roko.Retrier, resp *Response, err error) (broke bool)
- func IsErrHavingStatus(err error, code int) bool
- func IsRetryableError(err error) bool
- func IsRetryableStatus(r *Response) bool
- func JobURL(buildURL, jobID string) string
- func NewUUID() string
- type AgentPauseRequest
- type AgentRegisterRequest
- type AgentRegisterResponse
- type AgentStopRequest
- type AgentTokenIdentity
- type AgentTracing
- type Annotation
- type Artifact
- type ArtifactBatch
- type ArtifactBatchCreateResponse
- type ArtifactBatchUpdateRequest
- type ArtifactPartETag
- type ArtifactSearchOptions
- type ArtifactState
- type ArtifactUploadAction
- type ArtifactUploadInstructions
- type Build
- type CacheBlob
- type CacheDigest
- type CacheEntryCommitReq
- type CacheEntryCommitResp
- type CacheEntryCreateReq
- type CacheEntryCreateResp
- type CacheEntryExpireReq
- type CacheEntryPeekReq
- type CacheEntryPeekResp
- type CacheEntryRetrieveReq
- type CacheEntryRetrieveResp
- type CacheKeyPart
- type CacheRegistryResp
- type Chunk
- type Client
- func (c *Client) AcceptJob(ctx context.Context, jobID string) (*Job, *Response, error)
- func (c *Client) AcquireJob(ctx context.Context, id string, headers ...Header) (*Job, *Response, error)
- func (c *Client) Annotate(ctx context.Context, jobId string, annotation *Annotation) (*Response, error)
- func (c *Client) AnnotationRemove(ctx context.Context, jobId, context, scope string) (*Response, error)
- func (c *Client) CacheEntryCommit(ctx context.Context, registry string, commit CacheEntryCommitReq) (CacheEntryCommitResp, *Response, error)
- func (c *Client) CacheEntryCreate(ctx context.Context, registry string, create CacheEntryCreateReq) (CacheEntryCreateResp, *Response, error)
- func (c *Client) CacheEntryExpire(ctx context.Context, registry string, expire CacheEntryExpireReq) (*Response, error)
- func (c *Client) CacheEntryPeekExists(ctx context.Context, registry string, peek CacheEntryPeekReq) (CacheEntryPeekResp, bool, *Response, error)
- func (c *Client) CacheEntryRetrieve(ctx context.Context, registry string, retrieve CacheEntryRetrieveReq) (CacheEntryRetrieveResp, bool, *Response, error)
- func (c *Client) CacheRegistry(ctx context.Context, registry string) (CacheRegistryResp, *Response, error)
- func (c *Client) CancelBuild(ctx context.Context, uuid string) (*Build, *Response, error)
- func (c *Client) Config() Config
- func (c *Client) Connect(ctx context.Context) (*Response, error)
- func (c *Client) CreateArtifacts(ctx context.Context, jobID string, batch *ArtifactBatch) (*ArtifactBatchCreateResponse, *Response, error)
- func (c *Client) Disconnect(ctx context.Context) (*Response, error)
- func (c *Client) ExistsMetaData(ctx context.Context, scope, id, key string) (*MetaDataExists, *Response, error)
- func (c *Client) FinishJob(ctx context.Context, job *Job, ignoreAgentInDispatches *bool) (*Response, error)
- func (c *Client) FromAgentRegisterResponse(reg *AgentRegisterResponse) *Client
- func (c *Client) FromPing(resp *Ping) *Client
- func (c *Client) GenerateGithubCodeAccessToken(ctx context.Context, repoURL, jobID string) (string, *Response, error)
- func (c *Client) GenerateRepositoryAccessToken(ctx context.Context, repoURL, jobID string) (string, *Response, error)
- func (c *Client) GetJobState(ctx context.Context, id string) (*JobState, *Response, error)
- func (c *Client) GetMetaData(ctx context.Context, scope, id, key string) (*MetaData, *Response, error)
- func (c *Client) GetSecret(ctx context.Context, req *GetSecretRequest) (*Secret, *Response, error)
- func (c *Client) GetTokenIdentity(ctx context.Context) (*AgentTokenIdentity, *Response, error)
- func (c *Client) Heartbeat(ctx context.Context) (*Heartbeat, *Response, error)
- func (c *Client) MetaDataKeys(ctx context.Context, scope, id string) ([]string, *Response, error)
- func (c *Client) New(conf Config) *Client
- func (c *Client) OIDCToken(ctx context.Context, methodReq *OIDCTokenRequest) (*OIDCToken, *Response, error)
- func (c *Client) Pause(ctx context.Context, pauseReq *AgentPauseRequest) (*Response, error)
- func (c *Client) Ping(ctx context.Context) (*Ping, *Response, error)
- func (c *Client) PipelineUploadStatus(ctx context.Context, jobId string, uuid string, headers ...Header) (*PipelineUploadStatus, *Response, error)
- func (c *Client) PromiseFailure(ctx context.Context, id string, req *JobPromiseFailureRequest) (*Response, error)
- func (c *Client) PromiseFailureWithRetry(ctx context.Context, id string, req *JobPromiseFailureRequest, ...) (int, error)
- func (c *Client) Register(ctx context.Context, regReq *AgentRegisterRequest) (*AgentRegisterResponse, *Response, error)
- func (c *Client) Resume(ctx context.Context) (*Response, error)
- func (c *Client) SaveHeaderTimes(ctx context.Context, jobId string, headerTimes *HeaderTimes) (*Response, error)
- func (c *Client) SearchArtifacts(ctx context.Context, buildID string, opt *ArtifactSearchOptions) ([]*Artifact, *Response, error)
- func (c *Client) ServerSpecifiedRequestHeaders() http.Header
- func (c *Client) SetMetaData(ctx context.Context, jobId string, metaData *MetaData) (*Response, error)
- func (c *Client) SetMetaDataBatch(ctx context.Context, jobId string, batch *MetaDataBatch) (*Response, error)
- func (c *Client) StartJob(ctx context.Context, job *Job) (*Response, error)
- func (c *Client) StepCancel(ctx context.Context, stepIdOrKey string, stepCancel *StepCancel) (*StepCancelResponse, *Response, error)
- func (c *Client) StepExport(ctx context.Context, stepIdOrKey string, stepGetRequest *StepExportRequest) (*StepExportResponse, *Response, error)
- func (c *Client) StepUpdate(ctx context.Context, stepIdOrKey string, stepUpdate *StepUpdate) (*Response, error)
- func (c *Client) Stop(ctx context.Context, stopReq *AgentStopRequest) (*Response, error)
- func (c *Client) StreamPings(ctx context.Context, agentID string, opts ...connect.ClientOption) (iter.Seq2[*agentedgev1.StreamPingsResponse, error], error)
- func (c *Client) UpdateArtifacts(ctx context.Context, jobID string, artifactStates []ArtifactState) (*Response, error)
- func (c *Client) UpdateJob(ctx context.Context, id string, attrs map[string]string) (*JobUpdateResponse, *Response, error)
- func (c *Client) UploadChunk(ctx context.Context, jobId string, chunk *Chunk) (*Response, error)
- func (c *Client) UploadPipeline(ctx context.Context, jobId string, pipeline *PipelineChange, headers ...Header) (*Response, error)
- type Config
- type ErrorResponse
- type GetSecretRequest
- type GithubCodeAccessTokenRequestdeprecated
- type GithubCodeAccessTokenResponsedeprecated
- type Header
- type HeaderTimes
- type Heartbeat
- type Job
- type JobFinishRequest
- type JobPromiseFailureRequest
- type JobState
- type JobUpdateResponse
- type MetaData
- type MetaDataBatch
- type MetaDataExists
- type OIDCToken
- type OIDCTokenRequest
- type Ping
- type PipelineChange
- type PipelineUploadStatus
- type RepositoryAccessTokenRequest
- type RepositoryAccessTokenResponse
- type Response
- type Secret
- type StepCancel
- type StepCancelResponse
- type StepExportRequest
- type StepExportResponse
- type StepUpdate
- type TracingExporter
- type UndecodableResponseError
Constants ¶
const ( CacheRegistryNotFound = "Cache registry not found" CacheEntryNotFound = "Cache entry not found" )
Cache API "not found" messages. The cache service returns HTTP 404 with one of these messages in the JSON body to indicate semantically-distinct cases.
Variables ¶
var ErrCacheEntryNotFound = errors.New("cache entry not found")
ErrCacheEntryNotFound is reserved for callers that want a sentinel for the "no entry" condition. The cache methods themselves report it via the (resp, exists, err) return shape; this value is exported for parity.
Functions ¶
func BreakOnNonRetryable ¶ added in v3.124.0
BreakOnNonRetryable calls r.Break() if the error from an API call is not worth retrying. An error is retryable if the response body could not be decoded, if the response has a retryable status code (429, 5xx), or if there was no response and the error is a retryable network-level error (connection reset, timeout, etc.). All other errors — including all non-429 4xx status codes — cause a break.
This should be called inside roko retry callbacks after every API call. If err is nil, this is a no-op. BreakOnNonRetryable returns true if it called r.Break() (i.e. the error is non-retryable). Callers can use this to avoid logging misleading retry information when the retrier is about to give up.
func IsErrHavingStatus ¶ added in v3.44.0
func IsRetryableError ¶
Looks at a bunch of connection related errors, and returns true if the error matches one of them.
func IsRetryableStatus ¶ added in v3.40.0
IsRetryableStatus returns true if the response's StatusCode is one that we should retry. Success statuses (2xx) are not considered retryable — they are not errors.
func JobURL ¶ added in v3.133.0
JobURL returns the URL that deep-links to a specific job on its build page, e.g. "https://buildkite.com/org/pipeline/builds/42#0190abcd-...".
Types ¶
type AgentPauseRequest ¶ added in v3.96.0
type AgentPauseRequest struct {
Note string `json:"note,omitempty"`
TimeoutInMinutes int `json:"timeout_in_minutes,omitempty"`
}
AgentPauseRequest is a call to pause the agent via the Buildkite Agent API.
type AgentRegisterRequest ¶
type AgentRegisterRequest struct {
Name string `json:"name"`
Hostname string `json:"hostname"`
OS string `json:"os"`
Arch string `json:"arch"`
ScriptEvalEnabled bool `json:"script_eval_enabled"`
IgnoreInDispatches bool `json:"ignore_in_dispatches"`
Priority string `json:"priority,omitempty"`
Version string `json:"version"`
Build string `json:"build"`
Tags []string `json:"meta_data"`
PID int `json:"pid,omitempty"`
MachineID string `json:"machine_id,omitempty"`
Features []string `json:"features"`
}
AgentRegisterRequest is a call to register on the Buildkite Agent API
type AgentRegisterResponse ¶
type AgentRegisterResponse struct {
UUID string `json:"id"`
Name string `json:"name"`
AccessToken string `json:"access_token"`
Endpoint string `json:"endpoint"`
RequestHeaders map[string]string `json:"request_headers"`
PingInterval int `json:"ping_interval"`
JobStatusInterval int `json:"job_status_interval"`
HeartbeatInterval int `json:"heartbeat_interval"`
Tags []string `json:"meta_data"`
Tracing *AgentTracing `json:"tracing,omitempty"`
}
AgentRegisterResponse is the response from the Buildkite Agent API
type AgentStopRequest ¶ added in v3.93.0
type AgentStopRequest struct {
Force bool `json:"force,omitempty"`
}
AgentStopRequest is a call to stop the agent via the Buildkite Agent API
type AgentTokenIdentity ¶ added in v3.114.1
type AgentTokenIdentity struct {
UUID string `json:"uuid"`
Description string `json:"description"`
TokenType string `json:"token_type"`
OrganizationSlug string `json:"organization_slug"`
OrganizationUUID string `json:"organization_uuid"`
ClusterUUID string `json:"cluster_uuid"`
ClusterName string `json:"cluster_name"`
OrganizationQueueUUID string `json:"organization_queue_uuid"`
OrganizationQueueKey string `json:"organization_queue_key"`
}
AgentTokenIdentity describes token identity information.
type AgentTracing ¶ added in v3.136.1
type AgentTracing struct {
Backend string `json:"backend"`
PropagateTraceparent bool `json:"propagate_traceparent"`
Exporter *TracingExporter `json:"exporter,omitempty"`
}
AgentTracing is control-plane tracing policy that may be included in the agent registration response when the agent advertises the control-plane-otlp-tracing capability. Design: https://linear.app/buildkite/issue/A-1641
type Annotation ¶
type Annotation struct {
Body string `json:"body,omitempty"`
Context string `json:"context,omitempty"`
Style string `json:"style,omitempty"`
Append bool `json:"append,omitempty"`
Priority int `json:"priority,omitempty"`
Scope string `json:"scope,omitempty"`
}
Annotation represents a Buildkite Agent API Annotation
type Artifact ¶
type Artifact struct {
// The ID of the artifact. The ID is assigned to it after a successful
// batch creation
ID string `json:"id"`
// The path to the artifact relative to the working directory
Path string `json:"path"`
// The absolute path to the artifact
AbsolutePath string `json:"absolute_path"`
// The glob path used to find this artifact
GlobPath string `json:"glob_path"`
// The size of the file in bytes
FileSize int64 `json:"file_size"`
// A SHA-1 hash of the uploaded file
Sha1Sum string `json:"sha1sum"`
// A SHA-2 256-bit hash of the uploaded file, possibly empty
Sha256Sum string `json:"sha256sum"`
// ID of the job that created this artifact (from API)
JobID string `json:"job_id"`
// UTC timestamp this artifact was considered created
CreatedAt time.Time `json:"created_at"`
// The HTTP url to this artifact once it's been uploaded
URL string `json:"url,omitempty"`
// The destination specified on the command line when this file was
// uploaded
UploadDestination string `json:"upload_destination,omitempty"`
// Information on how to upload this artifact.
UploadInstructions *ArtifactUploadInstructions `json:"-"`
// A specific Content-Type to use on upload
ContentType string `json:"content_type,omitempty"`
}
Artifact represents an artifact on the Buildkite Agent API
type ArtifactBatch ¶
type ArtifactBatchCreateResponse ¶
type ArtifactBatchCreateResponse struct {
ID string `json:"id"`
ArtifactIDs []string `json:"artifact_ids"`
// These instructions apply to all artifacts. The template contains
// variable interpolations such as ${artifact:path}.
InstructionsTemplate *ArtifactUploadInstructions `json:"upload_instructions"`
// These instructions apply to specific artifacts, necessary for multipart
// uploads. It overrides InstructionTemplate and should not contain
// interpolations. Map: artifact ID -> instructions for that artifact.
PerArtifactInstructions map[string]*ArtifactUploadInstructions `json:"per_artifact_instructions"`
}
type ArtifactBatchUpdateRequest ¶
type ArtifactBatchUpdateRequest struct {
Artifacts []ArtifactState `json:"artifacts"`
}
type ArtifactPartETag ¶ added in v3.83.0
ArtifactPartETag associates an ETag to a part number for a multipart upload.
type ArtifactSearchOptions ¶
type ArtifactSearchOptions struct {
Query string `url:"query,omitempty"`
Scope string `url:"scope,omitempty"`
State string `url:"state,omitempty"`
IncludeRetriedJobs bool `url:"include_retried_jobs,omitempty"`
IncludeDuplicates bool `url:"include_duplicates,omitempty"`
}
ArtifactSearchOptions specifies the optional parameters to the ArtifactsService.Search method.
type ArtifactState ¶ added in v3.83.0
type ArtifactState struct {
ID string `json:"id"`
State string `json:"state"`
Multipart bool `json:"multipart,omitempty"`
// If this artifact was a multipart upload and is complete, we need the
// the ETag from each uploaded part so that they can be joined together.
MultipartETags []ArtifactPartETag `json:"multipart_etags,omitempty"`
}
ArtifactState represents the state of a single artifact, when calling UpdateArtifacts.
type ArtifactUploadAction ¶ added in v3.83.0
type ArtifactUploadAction struct {
URL string `json:"url,omitempty"`
Method string `json:"method"`
Path string `json:"path"`
FileInput string `json:"file_input"`
PartNumber int `json:"part_number,omitempty"`
}
ArtifactUploadAction describes one action needed to upload an artifact or part of an artifact to Buildkite artifact storage.
type ArtifactUploadInstructions ¶
type ArtifactUploadInstructions struct {
// Used for a single-part upload.
Action ArtifactUploadAction `json:"action"`
// Used for a multi-part upload.
Actions []ArtifactUploadAction `json:"actions"`
// Contains other data necessary for interpreting instructions.
Data map[string]string `json:"data"`
}
ArtifactUploadInstructions describes how to upload an artifact to Buildkite artifact storage.
type CacheBlob ¶ added in v3.128.0
type CacheBlob struct {
Digest CacheDigest `json:"digest"`
FileSize int64 `json:"file_size"`
Compression string `json:"compression"` // "zstd" | "zip"
}
CacheBlob describes one content-addressed blob backing a cache entry. The digest doubles as the storage object name. Length-1 array in M1; the array shape is future-proofing for content-defined chunking.
type CacheDigest ¶ added in v3.128.0
type CacheDigest struct {
Algorithm string `json:"algorithm"` // "sha256"
Value string `json:"value"`
}
CacheDigest is a typed content digest, so the algorithm can change without a wire break.
type CacheEntryCommitReq ¶ added in v3.127.2
type CacheEntryCommitReq struct {
UploadID string `json:"upload_id"`
ETags []string `json:"e_tags,omitempty"`
}
CacheEntryCommitReq is the request body for committing a created cache entry. e_tags is required for non-local store adapters and ignored for local ones.
type CacheEntryCommitResp ¶ added in v3.127.2
type CacheEntryCommitResp struct {
Message string `json:"message"`
}
CacheEntryCommitResp acknowledges a commit.
type CacheEntryCreateReq ¶ added in v3.127.2
type CacheEntryCreateReq struct {
TargetPaths []string `json:"target_paths"`
CacheKey []CacheKeyPart `json:"cache_key"`
Blobs []CacheBlob `json:"blobs"`
Platform string `json:"platform"`
}
CacheEntryCreateReq is the request body for creating (storing) a cache entry.
type CacheEntryCreateResp ¶ added in v3.127.2
type CacheEntryCreateResp struct {
UploadID string `json:"upload_id"`
Multipart bool `json:"multipart"`
UploadInstructions []string `json:"upload_instructions"`
Message string `json:"message"`
}
CacheEntryCreateResp describes how to upload the new cache entry. The storage object name is not echoed back — the agent derives it from the blob digest.
type CacheEntryExpireReq ¶ added in v3.132.0
type CacheEntryExpireReq struct {
TargetPaths []string `json:"target_paths"`
CacheKey []CacheKeyPart `json:"cache_key"`
}
CacheEntryExpireReq is the request body for invalidating a cache entry. The address should be the resolved entry, as echoed by the retrieve response.
type CacheEntryPeekReq ¶ added in v3.127.2
type CacheEntryPeekReq struct {
TargetPaths []string `json:"target_paths"`
CacheKey []CacheKeyPart `json:"cache_key"`
}
CacheEntryPeekReq is the request body for checking whether an entry exists.
type CacheEntryPeekResp ¶ added in v3.127.2
type CacheEntryPeekResp struct {
TargetPaths []string `json:"target_paths"`
CacheKey []CacheKeyPart `json:"cache_key"`
Blobs []CacheBlob `json:"blobs"`
Store string `json:"store"`
Message string `json:"message"`
}
CacheEntryPeekResp describes the cache entry returned by a peek.
type CacheEntryRetrieveReq ¶ added in v3.127.2
type CacheEntryRetrieveReq struct {
TargetPaths []string `json:"target_paths"`
CacheKey []CacheKeyPart `json:"cache_key"`
}
CacheEntryRetrieveReq is the request body for retrieving a cache entry.
type CacheEntryRetrieveResp ¶ added in v3.127.2
type CacheEntryRetrieveResp struct {
TargetPaths []string `json:"target_paths"`
CacheKey []CacheKeyPart `json:"cache_key"`
Blobs []CacheBlob `json:"blobs"`
ExpiresAt time.Time `json:"expires_at"`
Store string `json:"store"`
Fallback bool `json:"fallback"`
Multipart bool `json:"multipart"`
DownloadInstructions []string `json:"download_instructions"`
Message string `json:"message"`
}
CacheEntryRetrieveResp describes the cache entry to download.
type CacheKeyPart ¶ added in v3.128.0
CacheKeyPart is one element of the structured cache_key sent on the wire. Mandatory parts must match for a cache hit.
type CacheRegistryResp ¶ added in v3.127.2
type CacheRegistryResp struct {
UUID string `json:"uuid"`
Name string `json:"name"`
Store string `json:"store"`
}
CacheRegistryResp describes a configured cache registry.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
A Client manages communication with the Buildkite Agent API.
func (*Client) AcceptJob ¶
AcceptJob accepts the passed in job. Returns the job with its finalized set of environment variables (when a job is accepted, the agents environment is applied to the job)
func (*Client) AcquireJob ¶
func (c *Client) AcquireJob(ctx context.Context, id string, headers ...Header) (*Job, *Response, error)
Acquires a job using its ID
func (*Client) Annotate ¶
func (c *Client) Annotate(ctx context.Context, jobId string, annotation *Annotation) (*Response, error)
Annotate a build in the Buildkite UI
func (*Client) AnnotationRemove ¶ added in v3.28.1
func (c *Client) AnnotationRemove(ctx context.Context, jobId, context, scope string) (*Response, error)
Remove an annotation from a build
func (*Client) CacheEntryCommit ¶ added in v3.127.2
func (c *Client) CacheEntryCommit(ctx context.Context, registry string, commit CacheEntryCommitReq) (CacheEntryCommitResp, *Response, error)
CacheEntryCommit marks a previously created cache entry as committed.
func (*Client) CacheEntryCreate ¶ added in v3.127.2
func (c *Client) CacheEntryCreate(ctx context.Context, registry string, create CacheEntryCreateReq) (CacheEntryCreateResp, *Response, error)
CacheEntryCreate creates a new cache entry and returns upload instructions.
func (*Client) CacheEntryExpire ¶ added in v3.132.0
func (c *Client) CacheEntryExpire(ctx context.Context, registry string, expire CacheEntryExpireReq) (*Response, error)
CacheEntryExpire invalidates a cache entry so a subsequent save re-uploads it.
func (*Client) CacheEntryPeekExists ¶ added in v3.127.2
func (c *Client) CacheEntryPeekExists(ctx context.Context, registry string, peek CacheEntryPeekReq) (CacheEntryPeekResp, bool, *Response, error)
CacheEntryPeekExists checks whether a cache entry exists. Returns (resp, true, _, nil) on hit, (resp, false, _, nil) on miss (HTTP 404 with CacheEntryNotFound), or (resp, false, _, err) on any other failure.
func (*Client) CacheEntryRetrieve ¶ added in v3.127.2
func (c *Client) CacheEntryRetrieve(ctx context.Context, registry string, retrieve CacheEntryRetrieveReq) (CacheEntryRetrieveResp, bool, *Response, error)
CacheEntryRetrieve retrieves download instructions for a cache entry. Returns (resp, true, _, nil) on hit (possibly via a fallback key), (resp, false, _, nil) on miss, or (resp, false, _, err) on any other failure.
func (*Client) CacheRegistry ¶ added in v3.127.2
func (c *Client) CacheRegistry(ctx context.Context, registry string) (CacheRegistryResp, *Response, error)
CacheRegistry retrieves information about a cache registry.
func (*Client) CancelBuild ¶ added in v3.84.0
CancelBuild cancels a build with the given UUID
func (*Client) Connect ¶
Connect connects the agent to the Buildkite Agent API (calls the connect method - it doesn't necessarily open a new underlying network connection!).
func (*Client) CreateArtifacts ¶
func (c *Client) CreateArtifacts(ctx context.Context, jobID string, batch *ArtifactBatch) (*ArtifactBatchCreateResponse, *Response, error)
CreateArtifacts takes a slice of artifacts, and creates them on Buildkite as a batch.
func (*Client) Disconnect ¶
Disconnect disconnects the agent from the Buildkite Agent API (calls the disconnect method - it doesn't necessarily close the underlying network connection!).
func (*Client) ExistsMetaData ¶
func (c *Client) ExistsMetaData(ctx context.Context, scope, id, key string) (*MetaDataExists, *Response, error)
Returns true if the meta data key has been set, false if it hasn't.
func (*Client) FinishJob ¶
func (c *Client) FinishJob(ctx context.Context, job *Job, ignoreAgentInDispatches *bool) (*Response, error)
FinishJob finishes the passed in job
func (*Client) FromAgentRegisterResponse ¶
func (c *Client) FromAgentRegisterResponse(reg *AgentRegisterResponse) *Client
FromAgentRegisterResponse returns a new instance using the access token and endpoint from the registration response
func (*Client) GenerateGithubCodeAccessToken ¶ added in v3.63.0
func (c *Client) GenerateGithubCodeAccessToken(ctx context.Context, repoURL, jobID string) (string, *Response, error)
GenerateGithubCodeAccessToken is retained for compatibility. Deprecated: use GenerateRepositoryAccessToken.
func (*Client) GenerateRepositoryAccessToken ¶ added in v3.136.0
func (*Client) GetJobState ¶
GetJobState returns the state of a given job
func (*Client) GetMetaData ¶
func (c *Client) GetMetaData(ctx context.Context, scope, id, key string) (*MetaData, *Response, error)
Gets the meta data value
func (*Client) GetTokenIdentity ¶ added in v3.114.1
GetTokenIdentity gets the identity information of an agent token.
func (*Client) MetaDataKeys ¶
func (*Client) New ¶ added in v3.97.0
New creates a new Client for the given config, while preserving other internal state such as request headers and the logger.
func (*Client) PipelineUploadStatus ¶ added in v3.44.0
func (*Client) PromiseFailure ¶ added in v3.128.0
func (c *Client) PromiseFailure(ctx context.Context, id string, req *JobPromiseFailureRequest) (*Response, error)
PromiseFailure declares a promised (early) exit-status failure for a job, allowing the build-failing cascade to begin before the job finishes. The job itself keeps running and finishes normally. On success the endpoint responds with 204 No Content and no body.
func (*Client) PromiseFailureWithRetry ¶ added in v3.130.0
func (c *Client) PromiseFailureWithRetry(ctx context.Context, id string, req *JobPromiseFailureRequest, warnf func(string, ...any)) (int, error)
PromiseFailureWithRetry declares a promised failure for the job, retrying transient errors with the agent's standard backoff. It returns the HTTP status of the most recent response (0 if none was received, e.g. a network error) and an error describing any failure. Retry attempts are logged via warnf.
func (*Client) Register ¶
func (c *Client) Register(ctx context.Context, regReq *AgentRegisterRequest) (*AgentRegisterResponse, *Response, error)
Registers the agent against the Buildkite Agent API. The client for this call must be authenticated using an Agent Registration Token
func (*Client) SaveHeaderTimes ¶
func (c *Client) SaveHeaderTimes(ctx context.Context, jobId string, headerTimes *HeaderTimes) (*Response, error)
SaveHeaderTimes saves the header times to the job
func (*Client) SearchArtifacts ¶
func (c *Client) SearchArtifacts(ctx context.Context, buildID string, opt *ArtifactSearchOptions) ([]*Artifact, *Response, error)
SearchArtifacts searches Buildkite for a set of artifacts
func (*Client) ServerSpecifiedRequestHeaders ¶ added in v3.97.0
ServerSpecifiedRequestHeaders returns the HTTP headers that the Buildkite register/ping APIs have advised the client to send in all requests.
func (*Client) SetMetaData ¶
func (c *Client) SetMetaData(ctx context.Context, jobId string, metaData *MetaData) (*Response, error)
Sets the meta data value
func (*Client) SetMetaDataBatch ¶ added in v3.129.0
func (c *Client) SetMetaDataBatch(ctx context.Context, jobId string, batch *MetaDataBatch) (*Response, error)
SetMetaDataBatch sets multiple meta data key/value pairs in a single request. The operation is transactional: all items succeed or none do.
func (*Client) StepCancel ¶ added in v3.85.0
func (c *Client) StepCancel(ctx context.Context, stepIdOrKey string, stepCancel *StepCancel) (*StepCancelResponse, *Response, error)
StepCancel cancels a step
func (*Client) StepExport ¶
func (c *Client) StepExport(ctx context.Context, stepIdOrKey string, stepGetRequest *StepExportRequest) (*StepExportResponse, *Response, error)
StepExport gets an attribute from step
func (*Client) StepUpdate ¶
func (c *Client) StepUpdate(ctx context.Context, stepIdOrKey string, stepUpdate *StepUpdate) (*Response, error)
StepUpdate updates a step
func (*Client) StreamPings ¶ added in v3.119.0
func (c *Client) StreamPings(ctx context.Context, agentID string, opts ...connect.ClientOption) (iter.Seq2[*agentedgev1.StreamPingsResponse, error], error)
StreamPings opens a ConnectRPC channel for streaming pings. It returns an iterator over received messages and any error that occurs.
func (*Client) UpdateArtifacts ¶
func (c *Client) UpdateArtifacts(ctx context.Context, jobID string, artifactStates []ArtifactState) (*Response, error)
UpdateArtifacts updates Buildkite with one or more artifact states.
func (*Client) UpdateJob ¶ added in v3.118.0
func (c *Client) UpdateJob(ctx context.Context, id string, attrs map[string]string) (*JobUpdateResponse, *Response, error)
UpdateJob updates mutable attributes on a job
func (*Client) UploadChunk ¶
Uploads the chunk to the Buildkite Agent API. This request sends the compressed log directly as a request body.
func (*Client) UploadPipeline ¶
func (c *Client) UploadPipeline( ctx context.Context, jobId string, pipeline *PipelineChange, headers ...Header, ) (*Response, error)
UploadPipeline uploads the pipeline to the Buildkite Agent API. It does not wait for the pipeline to finish processing but will instead return with a redirect to the location to check the pipeline's status.
type Config ¶
type Config struct {
// Endpoint for API requests. Defaults to the public Buildkite Agent API.
// The URL should always be specified with a trailing slash.
Endpoint string
// The authentication token to use, either a registration or access token
Token string
// User agent used when communicating with the Buildkite Agent API.
UserAgent string
// If true, only HTTP2 is disabled
DisableHTTP2 bool
// If true, requests and responses will be dumped and set to the logger
DebugHTTP bool
// If true timings for each request will be logged
TraceHTTP bool
// The http client used, leave nil for the default
HTTPClient *http.Client
// optional TLS configuration primarily used for testing
TLSConfig *tls.Config
// HTTP client timeout; zero to use default
Timeout time.Duration
}
Config is configuration for the API Client
type ErrorResponse ¶
type ErrorResponse struct {
Response *http.Response // HTTP response that caused this error
Message string `json:"message"` // error message
// Details of a response body that wasn't an API error message. Taken from the
// response, never decoded from it, hence `json:"-"`.
ContentType string `json:"-"`
Snippet string `json:"-"`
}
ErrorResponse provides a message.
func (*ErrorResponse) Error ¶
func (r *ErrorResponse) Error() string
type GetSecretRequest ¶ added in v3.64.0
GetSecretRequest represents a request to read a secret from the Buildkite Agent API.
type GithubCodeAccessTokenRequest
deprecated
added in
v3.63.0
type GithubCodeAccessTokenRequest = RepositoryAccessTokenRequest
Deprecated: use RepositoryAccessTokenRequest.
type GithubCodeAccessTokenResponse
deprecated
added in
v3.63.0
type GithubCodeAccessTokenResponse = RepositoryAccessTokenResponse
Deprecated: use RepositoryAccessTokenResponse.
type HeaderTimes ¶
HeaderTimes represents a set of header times that are associated with a job log.
type Heartbeat ¶
type Heartbeat struct {
SentAt string `json:"sent_at"`
ReceivedAt string `json:"received_at,omitempty"`
}
Heartbeat represents a Buildkite Agent API Heartbeat
type Job ¶
type Job struct {
ID string `json:"id"`
Endpoint string `json:"endpoint"`
State string `json:"state"`
Env map[string]string `json:"env"`
Step pipeline.CommandStep `json:"step"`
MatrixPermutation pipeline.MatrixPermutation `json:"matrix_permutation"`
ChunksMaxSizeBytes uint64 `json:"chunks_max_size_bytes"`
ChunksIntervalSeconds int `json:"chunks_interval_seconds"`
LogMaxSizeBytes uint64 `json:"log_max_size_bytes"`
Token string `json:"token"`
ExitStatus string `json:"exit_status"`
Signal string `json:"signal"`
SignalReason string `json:"signal_reason"`
StartedAt string `json:"started_at"`
FinishedAt string `json:"finished_at"`
RunnableAt string `json:"runnable_at"`
ChunksFailedCount int `json:"chunks_failed_count"`
TraceParent string `json:"traceparent"`
TraceState string `json:"tracestate"`
Priority int `json:"priority"`
}
Job represents a Buildkite Agent API Job
type JobFinishRequest ¶ added in v3.97.1
type JobFinishRequest struct {
ExitStatus string `json:"exit_status,omitempty"`
Signal string `json:"signal,omitempty"`
SignalReason string `json:"signal_reason,omitempty"`
FinishedAt string `json:"finished_at,omitempty"`
ChunksFailedCount int `json:"chunks_failed_count"`
IgnoreAgentInDispatches *bool `json:"ignore_agent_in_dispatches,omitempty"`
}
type JobPromiseFailureRequest ¶ added in v3.128.0
type JobPromiseFailureRequest struct {
ExitStatus int `json:"exit_status"`
Reason string `json:"reason,omitempty"`
}
JobPromiseFailureRequest declares a promised (early) exit-status failure for a job. ExitStatus must be a non-zero integer; the server rejects zero, non-integer, and out-of-range values.
type JobUpdateResponse ¶ added in v3.118.0
type JobUpdateResponse struct {
ID string `json:"id"`
}
JobUpdateResponse is the response from updating a job
type MetaDataBatch ¶ added in v3.129.0
type MetaDataBatch struct {
Items []MetaData `json:"items"`
}
MetaDataBatch represents a batch of key/value pairs for the set-batch endpoint.
type MetaDataExists ¶
type MetaDataExists struct {
Exists bool `json:"exists"`
}
MetaDataExists represents a Buildkite Agent API MetaData Exists check response
type OIDCTokenRequest ¶ added in v3.41.0
type Ping ¶
type Ping struct {
Action string `json:"action,omitempty"`
Message string `json:"message,omitempty"`
Job *Job `json:"job,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
RequestHeaders map[string]string `json:"request_headers,omitzero"` // omit nil, keep empty map
}
Ping represents a Buildkite Agent API Ping
type PipelineChange ¶ added in v3.44.0
type PipelineChange struct {
// UUID identifies this pipeline change. We keep this constant during
// retry loops so that work is not repeated on the API server
UUID string `json:"uuid"`
Pipeline any `json:"pipeline"`
Replace bool `json:"replace,omitempty"`
}
PipelineChange represents a Buildkite Agent API PipelineChange
type PipelineUploadStatus ¶ added in v3.44.0
type RepositoryAccessTokenRequest ¶ added in v3.136.0
type RepositoryAccessTokenRequest struct {
RepoURL string `json:"repo_url,omitempty"`
}
type RepositoryAccessTokenResponse ¶ added in v3.136.0
type RepositoryAccessTokenResponse struct {
Token string `json:"token,omitempty"`
}
type Secret ¶ added in v3.64.0
type Secret struct {
Key string `json:"key"`
Value string `json:"value"`
UUID string `json:"uuid"`
}
Secret represents a secret read from the Buildkite Agent API.
type StepCancel ¶ added in v3.85.0
type StepCancelResponse ¶ added in v3.85.0
type StepCancelResponse struct {
UUID string `json:"uuid"`
}
type StepExportRequest ¶
type StepExportRequest struct {
Attribute string `json:"attribute,omitempty"`
Build string `json:"build_id,omitempty"`
Format string `json:"format,omitempty"`
}
StepExportRequest represents a request for information about a step
type StepExportResponse ¶
type StepExportResponse struct {
Output string `json:"output"`
}
type StepUpdate ¶
type StepUpdate struct {
IdempotencyUUID string `json:"idempotency_uuid,omitempty"`
Build string `json:"build_id,omitempty"`
Attribute string `json:"attribute,omitempty"`
Value string `json:"value,omitempty"`
Append bool `json:"append,omitempty"`
}
StepUpdate represents a change request to a step
type TracingExporter ¶ added in v3.136.1
type TracingExporter struct {
Endpoint string `json:"endpoint"`
Protocol string `json:"protocol"`
Headers map[string]string `json:"headers,omitempty"`
}
TracingExporter is an OTLP trace exporter destination supplied by the control plane. Headers may carry vendor credentials (e.g. an Authorization header): raw endpoints and headers must not be logged or written to the persisted job-env files, though the exporter is intentionally delivered through the bootstrap process environment so hooks and the job command can export spans to the same collector.
type UndecodableResponseError ¶ added in v3.137.1
type UndecodableResponseError struct {
Method string // request method
URL string // request URL, after any redirects
Status string // response status
ContentType string // response content type
Snippet string // start of the response body; empty when it could hold credentials
Err error // the decoding error
}
UndecodableResponseError is returned when a response had a success status but a body that could not be decoded. Usually this means something other than the Buildkite Agent API answered the request - a proxy, load balancer, or CDN serving its own error page - which makes it worth retrying. See IsRetryableError.
func (*UndecodableResponseError) Error ¶ added in v3.137.1
func (e *UndecodableResponseError) Error() string
func (*UndecodableResponseError) Unwrap ¶ added in v3.137.1
func (e *UndecodableResponseError) Unwrap() error