简体   繁体   中英

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? . ie 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.

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 (eg 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.

There are lots of environment variables, but in my experience they are not very reliable as they depend on how the build is triggered. The most useful ones seem to be:

echo "Region = ${AWS_REGION}"
echo "Account Id = $(echo $CODEBUILD_BUILD_ARN | cut -f5 -d ':')"
echo "Repo Name = $(echo $CODEBUILD_SOURCE_VERSION | cut -f2 -d '/')"
echo "Commit Id = ${CODEBUILD_RESOLVED_SOURCE_VERSION}"

Which outputs:

Region = us-west-2
Account Id = 0123456789
Repo Name = my-app
Commit Id = a46218c9160f932f2a91748a449b3f9818964642

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM