feat(buildkite): pass through BuildMetadata#206
Merged
Conversation
behinddwalls
approved these changes
Jun 5, 2026
e3b790b to
55cf865
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Thread
BuildMetadatathrough the BuildkiteBuildRunnerso callers can attach attributes (requester, ticket ID, trace ID) at trigger time and recover them from any subsequentStatuscall— with no local state required.
Trigger: JSON-encodes the caller-supplied metadata into a newSQ_METADATAenv var on the Buildkite build request. Omitted when metadata is nil/empty, keeping the payload clean forcallers that don't use it.
Status: decodesSQ_METADATAfrom the env vars Buildkite echoes back on the build object, merges with"url", and returns the combined map. Decode errors are swallowed — a corruptenv var must not fail a status poll.
client.go: addsEnv map[string]stringtobuildResponseto capture the echoed env vars from the Buildkite GET response.Why?
The
BuildRunnerinterface documents thatmetadata"MAY be persisted or echoed back via Status" — but the original implementation discarded it with_. Buildkite's REST API echoes thebuild's
envmap on every GET response, which means the metadata can round-trip through Buildkite itself rather than requiring a separate store or in-memory cache. This keeps theimplementation stateless and satisfies the interface contract at no extra infrastructure cost.
Tests
TestTrigger_WithMetadata_SetsEnvVar— captures the outbound request body, verifiesSQ_METADATAis present, and round-trips the JSON back intoBuildMetadatato assert key equality.TestTrigger_NilMetadata_NoMetadataEnvVar— verifies nil metadata produces noSQ_METADATAkey (i.e. the env map stays clean).TestStatus_EchosCallerMetadata— serves a build response withSQ_METADATAset; asserts all caller keys and"url"are present in the returned metadata.TestStatus_NoMetadata_ReturnsOnlyURL— build response withoutSQ_METADATA; asserts the returned map is exactly{"url": "..."}, confirming the no-metadata path is unaffected.