[英]How can I use env variables in this buildspec.yml file?
I've been building out this buildspec.yml
file to configure my CodeBuild integration and while I can inject variables everywhere else in the script, it fails when I try to repeat the pattern in the printf
section shown below.我一直在构建这个
buildspec.yml
文件来配置我的 CodeBuild 集成,虽然我可以在脚本的其他地方注入变量,但当我尝试在下面显示的printf
部分重复模式时它失败了。 I'm out of ideas in regards to setting it up and I'm curious if anyone can point me in the right direction.我对设置它没有想法,我很好奇是否有人能指出我正确的方向。
version: 0.2
phases:
pre_build:
commands:
- echo Logging in to Amazon ECR...
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .
- docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker image...
- docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$IMAGE_TAG
- echo Writing image definitions file...
- printf '[{"name":"<HOW_TO_PLACE_VAR_HERE>","imageUri":"<HOW_TO_PLACE_VAR_HERE>"}]' $IMAGE_REPO_NAME:$IMAGE_TAG > imagedefinitions.json
^ how would I inject variables here? the $PATTERN doesn't work.
artifacts:
files:
- '**/*'
- 'imagedefinitions.json'
name: s3-to-s3-latest-build.zip
discard-paths: no
printf '[{"name":"<HOW_TO_PLACE_VAR_HERE>","imageUri":"<HOW_TO_PLACE_VAR_HERE>"}]' $IMAGE_REPO_NAME:$IMAGE_TAG > imagedefinitions.json
printf '[{"name":"<HOW_TO_PLACE_VAR_HERE>","imageUri":"<HOW_TO_PLACE_VAR_HERE>"}]' $IMAGE_REPO_NAME:$IMAGE_TAG > imagedefinitions.json
Firstly, you are sending the output to a file, so probably you have not checked the actual contents.首先,您将输出发送到文件,因此您可能没有检查实际内容。
Secondly, you can go with echo
statement as you have used elsewhere其次,您可以使用您在其他地方使用过的
echo
语句
echo '[{"name":"'$IMAGE_REPO_NAME'"}]'
echo '[{"name":"'$IMAGE_REPO_NAME'"}]'
you can still send the contents to a file by redirecting the stdout to required file您仍然可以通过将标准输出重定向到所需文件来将内容发送到文件
echo '[{"name":"'$IMAGE_REPO_NAME'"}]' > imagedefinitions.json
echo '[{"name":"'$IMAGE_REPO_NAME'"}]' > imagedefinitions.json
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.