Reputation: 403
Environment variables declared within the Codebuild console, are not getting resolved.
I've tried as many variations of variable usage with YAML as I could think of;
$VARIABLE
${VARIABLE}
"$VARIABLE"
version: 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. Where key is the name I want to use, and value is the name of the variable/parameter to get the value from.
When running in Codebuild, the output simply shows exactly what's written, rather than replacing the variables...
Upvotes: 3
Views: 5485
Reputation: 133
try using echo first to see you can see the value. I used as follows it worked for me
version: 0.2
env:
variables:
key: "value"
pre_build:
commands:
- echo ${key}
Upvotes: 0
Reputation: 5655
Just remove block chomping indicator, >-, after "commands:". That just prevents variable substitution.
You can use either $VARIABLE or ${VARIABLE} in your buildspec.
Upvotes: 1