Open
Conversation
Maps CodeBuild-specific env vars to neutral industry-standard names and injects them into the build environment: - CODEBUILD_WEBHOOK_HEAD_REF (or CODEBUILD_SOURCE_VERSION) → CI_COMMIT_REF - CODEBUILD_RESOLVED_SOURCE_VERSION → CI_COMMIT_SHA - CODEBUILD_START_TIME → CI_BUILD_STARTED_AT - CODEBUILD_SOURCE_REPO_URL → CI_REPOSITORY_URL Closes #13 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a translation layer from AWS CodeBuild environment variables to neutral, commonly-used CI variable names and ensures they’re available inside Dockerfile/buildpack builds.
Changes:
- Populate
CI_COMMIT_REF,CI_COMMIT_SHA,CI_BUILD_STARTED_AT, andCI_REPOSITORY_URLinLoadBuildEnv()based on CodeBuild-provided env vars (with a ref fallback). - Add unit tests covering the new CI var population and the
CI_COMMIT_REFfallback behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| builder/build/build.go | Adds mapping from CodeBuild env vars to standard CI variable names in the build environment map. |
| builder/build/build_test.go | Adds tests verifying the mapped CI variables and fallback behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| mockedAWS.On("GetParametersByPath", appConfigPrefix).Return(map[string]string{}, nil) | ||
| mockedState := emptyState() | ||
| mockedState.On("ReadEnvFile").Return(&map[string]string{}, nil) | ||
|
|
builder/build/build.go
Outdated
Comment on lines
+42
to
+45
| env["CI_COMMIT_REF"] = GetenvFallback([]string{"CODEBUILD_WEBHOOK_HEAD_REF", "CODEBUILD_SOURCE_VERSION"}) | ||
| env["CI_COMMIT_SHA"] = os.Getenv("CODEBUILD_RESOLVED_SOURCE_VERSION") | ||
| env["CI_BUILD_STARTED_AT"] = os.Getenv("CODEBUILD_START_TIME") | ||
| env["CI_REPOSITORY_URL"] = os.Getenv("CODEBUILD_SOURCE_REPO_URL") |
builder/build/build.go
Outdated
| if val, ok := os.LookupEnv("ALLOW_EOL_SHIMMED_BUILDER"); ok { | ||
| env["ALLOW_EOL_SHIMMED_BUILDER"] = val | ||
| } | ||
| // map CodeBuild-specific vars to neutral CI vars and pass as build args |
- Only set CI_* vars when source env var is non-empty - Fix comment: vars are build args in Docker, env vars in buildpacks - Explicitly unset CODEBUILD_WEBHOOK_HEAD_REF in fallback test for determinism Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
CODEBUILD_WEBHOOK_HEAD_REF(falls back toCODEBUILD_SOURCE_VERSIONfor manual builds) →CI_COMMIT_REFCODEBUILD_RESOLVED_SOURCE_VERSION→CI_COMMIT_SHACODEBUILD_START_TIME→CI_BUILD_STARTED_ATCODEBUILD_SOURCE_REPO_URL→CI_REPOSITORY_URLTest Plan
TestLoadBuildEnvCIVars— verifies all four CI vars are populated from CodeBuild env varsTestLoadBuildEnvCIVarsFallback— verifiesCI_COMMIT_REFfalls back toCODEBUILD_SOURCE_VERSIONwhenCODEBUILD_WEBHOOK_HEAD_REFis not set (manual builds)Closes #13
🤖 Generated with Claude Code