Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CodeBuild environment variables for versioning?

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.

like image 489
vicsz Avatar asked Jan 31 '17 14:01

vicsz


People also ask

How do I set environment variables in CodeBuild?

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.

What is the build environment for CodeBuild?

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.

What does the variable Codebuild_build_number used for?

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.

How do you use environment variables in Buildspec yml?

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.


2 Answers

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!

like image 189
awsnitin Avatar answered Oct 02 '22 09:10

awsnitin


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.
like image 33
Serena Yu Avatar answered Oct 02 '22 09:10

Serena Yu