Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 在for循环内执行if-else条件时代码生成出错_Bash_Amazon Web Services_Shell_Jq_Aws Codebuild - Fatal编程技术网

Bash 在for循环内执行if-else条件时代码生成出错

Bash 在for循环内执行if-else条件时代码生成出错,bash,amazon-web-services,shell,jq,aws-codebuild,Bash,Amazon Web Services,Shell,Jq,Aws Codebuild,下面是我的buildspec.yaml文件,其中列出了ecr中的图像,我正在使用它进行循环,以及查找特定imageId的条件是否存在 version: 0.2 phases: install: runtime-versions: nodejs: 12 commands: - echo test pre_build: commands: - echo Logging in to Amazon ECR... - aw

下面是我的buildspec.yaml文件,其中列出了ecr中的图像,我正在使用它进行循环,以及查找特定imageId的条件是否存在

version: 0.2

phases:

  install:
    runtime-versions:
      nodejs: 12
    commands:
      - echo test
  pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      - aws --version
      - $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)

  build:
    commands:
      - aws ecr list-images --repository-name mytestecrrepo > ecr.json
      - cat ecr.json
      - for imageTag in $(jq -r '.imageIds[].imageTag' < ecr.json); do 
        if [ $imageTag = "1.0" ]; then 
        echo "value exists" 
        else 
        echo "value doesntexists" 
        fi 
        done
  post_build:
    commands:
      - echo Build completed on `date`
版本:0.2
阶段:
安装:
运行时版本:
nodejs:12
命令:
-回声测试
预构建:
命令:
-echo登录亚马逊ECR。。。
-aws——版本
-$(aws ecr get login--区域$aws\u默认\u区域--不包括电子邮件)
建造:
命令:
-aws ecr列表图像--存储库名称MyTesteCrepo>ecr.json
-cat ecr.json
-对于$(jq-r'.imageIds[].imageTag'
出于某种原因,代码生成抛出以下错误

/codebuild/output/tmp/script.sh:第9行:语法错误:文件意外结束


我在shell脚本中出错了?

您可以在
构建中尝试以下操作:

  build:
    commands:
      - aws ecr list-images --repository-name mytestecrrepo > ecr.json
      - cat ecr.json
      - |
        for imageTag in $(jq -r '.imageIds[].imageTag' < ecr.json); do 
        if [ $imageTag = "1.0" ]; then 
        echo "value exists" 
        else 
        echo "value doesntexists" 
        fi 
        done
构建:
命令:
-aws ecr列表图像--存储库名称MyTesteCrepo>ecr.json
-cat ecr.json
- |
对于$(jq-r'.imageIds[].imageTag'