Skip to content

Pass standard CI vars as build args (fixes #13)#24

Open
ipmb wants to merge 3 commits intomainfrom
pass-ci-vars-as-build-args
Open

Pass standard CI vars as build args (fixes #13)#24
ipmb wants to merge 3 commits intomainfrom
pass-ci-vars-as-build-args

Conversation

@ipmb
Copy link
Member

@ipmb ipmb commented Mar 17, 2026

Summary

  • Maps CodeBuild-specific environment variables to neutral, industry-standard CI names and injects them into Docker/buildpack build environments as build args
  • CODEBUILD_WEBHOOK_HEAD_REF (falls back to CODEBUILD_SOURCE_VERSION for manual builds) → CI_COMMIT_REF
  • CODEBUILD_RESOLVED_SOURCE_VERSIONCI_COMMIT_SHA
  • CODEBUILD_START_TIMECI_BUILD_STARTED_AT
  • CODEBUILD_SOURCE_REPO_URLCI_REPOSITORY_URL

Test Plan

  • Added TestLoadBuildEnvCIVars — verifies all four CI vars are populated from CodeBuild env vars
  • Added TestLoadBuildEnvCIVarsFallback — verifies CI_COMMIT_REF falls back to CODEBUILD_SOURCE_VERSION when CODEBUILD_WEBHOOK_HEAD_REF is not set (manual builds)
  • All existing tests continue to pass

Closes #13

🤖 Generated with Claude Code

ipmb and others added 2 commits March 17, 2026 13:39
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>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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, and CI_REPOSITORY_URL in LoadBuildEnv() based on CodeBuild-provided env vars (with a ref fallback).
  • Add unit tests covering the new CI var population and the CI_COMMIT_REF fallback 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)

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")
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>
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.

Pass common CI vars into builder as build args

2 participants