gpt4 book ai didi

amazon-web-services - 如何在代码构建中将命令的输出分配给变量

转载 作者:行者123 更新时间:2023-12-05 04:06:49 25 4
gpt4 key购买 nike

每当推送到我的源代码并将 docker 镜像移动到 ECR(EC2 容器注册表)时,我都会尝试构建一个 docker 镜像。

我已尝试使用以下构建规范文件

    version: 0.2
env:
variables:
IMG: "app"
REPO: "<<zzzzzzzz>>.dkr.ecr.us-east-1.amazonaws.com/app"
phases:
pre_build:
commands:
- echo Logging in to Amazon ECR...
- aws ecr get-login --region us-east-1
- TAG=echo $CODEBUILD_RESOLVED_SOURCE_VERSION | head -c 8
build:
commands:
- echo $TAG
- docker build -t $IMG:$TAG .
- docker tag $IMG:$TAG $REPO:$TAG
post_build:
commands:
- docker push $REPO:$TAG
- printf Image":"%s:%s" $REPO $TAG > build.json
artifacts:
files: build.json
discard-paths: yes

当我构建它时,我在 docker build -t 收到错误 invalid reference format

我查看了文档,没有找到任何帮助。

最佳答案

TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | head -c 8)

你可以使用 $()

version: 0.2

phases:
install:
commands:
- echo Entered the install phase...
- TAG=$(echo "This is test")
pre_build:
commands:
- echo $TAG
build:
commands:
- echo Entered the build phase...
- echo Build started on $TAG

日志:

[Container] 2018/03/17 16:15:31 Running command TAG=$(echo "This is test")
[Container] 2018/03/17 16:15:31 Entering phase PRE_BUILD
[Container] 2018/03/17 16:15:31 Running command echo $TAG
This is test

关于amazon-web-services - 如何在代码构建中将命令的输出分配给变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49334876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com