[英]How to use environment variables defined in the Codebuild console, within the buildspec.yml
Environment variables declared within the Codebuild console, are not getting resolved.在 Codebuild 控制台中声明的环境变量没有得到解决。
I've tried as many variations of variable usage with YAML as I could think of;我已经尝试了尽可能多的 YAML 变量用法变体;
$VARIABLE
${VARIABLE}
"$VARIABLE"
version: 0.2版本:0.2
env:
variables:
AWS_S3_BUCKET_NAME: "AWS_S3_BUCKET_NAME"
API_URL: "API_URL"
parameter_store:
aws_access_key: "my-access-key"
aws_secret_key: "my-secret-key"
phases:
install:
runtime-versions:
python: 3.7
post_build:
commands: >-
AWS_REGION=${AWS_REGION}
SOURCE_REPO_URL=${CODEBUILD_SOURCE_REPO_URL}
SOURCE_BRANCH=${CODEBUILD_SOURCE_VERSION}
AWS_S3_BUCKET_NAME=${AWS_S3_BUCKET_NAME}
AWS_ACCESS_KEY=${aws_access_key}
AWS_SECRET_KEY=${aws_secret_key}
// custom script
The docs specify you need to have this env structure of key/value pairs.文档指定您需要具有此键/值对的 env 结构。 Where key is the name I want to use, and value is the name of the variable/parameter to get the value from.其中 key 是我要使用的名称,value 是从中获取值的变量/参数的名称。
When running in Codebuild, the output simply shows exactly what's written, rather than replacing the variables...在 Codebuild 中运行时,输出只是准确地显示所写的内容,而不是替换变量......
Just remove block chomping indicator, >- , after "commands:" .只需在"commands:"之后删除块咀嚼指示符>- 。 That just prevents variable substitution.这只是防止变量替换。
You can use either $VARIABLE or ${VARIABLE} in your buildspec.您可以在构建规范中使用 $VARIABLE 或 ${VARIABLE}。
try using echo first to see you can see the value.首先尝试使用 echo 来查看您可以看到的值。 I used as follows it worked for me我使用如下它对我有用
version: 0.2
env:
variables:
key: "value"
pre_build:
commands:
- echo ${key}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.