简体   繁体   English

用于版本控制的 AWS CodeBuild 环境变量?

[英]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?是否有任何类型的 AWS CodeBuild 环境变量可以帮助在构建工件上标记版本信息? . . ie the equivalents of what Bamboo has such as bamboo_buildNumber .即 Bamboo 所拥有的等价物,例如bamboo_buildNumber Ideally I would want both build number and SCM number.理想情况下,我想要内部版本号和 SCM 号。

The docs talk about CODEBUILD_x variables for internal use, but I'm unable to find a listing of them.文档讨论了供内部使用的CODEBUILD_x变量,但我找不到它们的列表。

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此处列出了 CodeBuild 提供的用于消费的环境变量的参考: 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.对于内部版本号相关信息,您可以使用 CODEBUILD_BUILD_ID 或 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_SOURCE_VERSION 或 CODEBUILD_SOURCE_REPO_URL 环境变量。

CodeBuild documentation is not yet updated with the detailed information of these updated environment variables. CodeBuild 文档尚未更新这些更新的环境变量的详细信息。

Thanks!谢谢!

Amazon has very recently added a BuildNumber environment variable.亚马逊最近添加了一个 BuildNumber 环境变量。

According to https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html根据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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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