Is there any type of AWS CodeBuild environment variables that can aid in stamping versioning information on build artifacts? . i.e. the equivalents of what Bamboo has such as bamboo_buildNumber
. Ideally I would want both build number and SCM number.
The docs talk about CODEBUILD_x
variables for internal use, but I'm unable to find a listing of them.
Choose the icon to edit your CodeBuild action. On the Edit action page, under Environment variables, enter the following: In Name, enter a name for your environment variable. In Value, enter the variable syntax for your pipeline output variable, which includes the namespace assigned to your source action.
A build environment represents a combination of operating system, programming language runtime, and tools that CodeBuild uses to run a build. For information about how a build environment works, see How CodeBuild works. A build environment contains a Docker image.
The artifacts section also uses the $CODEBUILD_BUILD_NUMBER variable as a namespace to better associate the reports with a specific build when sending to the S3 bucket. For more details on how to configure artifacts in a project build, read the artifacts section in the AWS CodeBuild buildspec reference guide.
When you create a codebuild you can pass environment variables. Then in your buildspec. yml you can refer them like regular environment variables with $IMAGE_REPO_NAME . What you can not do is create only 1 codebuild and pass variables to it like a script, so you need to create 2 codebuilds, but 1 buildspec.
Reference to environment variables vended by CodeBuild for consumption is listed here: http://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref.html#build-env-ref-env-vars
For build number related information, you can use CODEBUILD_BUILD_ID or CODEBUILD_BUILD_ARN. For the source related information, depending on how the build was triggered and what the input parameters to the build were (e.g. if you've specified source version while starting your build -- reference), you can additionally use CODEBUILD_SOURCE_VERSION or CODEBUILD_SOURCE_REPO_URL environment variables.
CodeBuild documentation is not yet updated with the detailed information of these updated environment variables.
Thanks!
Amazon has very recently added a BuildNumber environment variable.
According to https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
CODEBUILD_BUILD_NUMBER: The current build number for the project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With