codebuild 错误退出状态 127 - 文件名太长

问题描述 投票:0回答:1

我对 aws 的实验不多,我正在尝试使用 codebuild 构建一个 docker 映像,然后将其发送到 ECR 存储库。

这是我的 buildspec.yml 文件:

version: 0.2

phases:
  pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      - aws --version
      - $(aws ecr get-login-password --region $AWS_DEFAULT_REGION)

      - REPOSITORY_URI= {URI}
      - COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
      - IMAGE_TAG=build-$(echo $CODEBUILD_BUILD_ID | awk -F":" '{print $2}')

  build:
    commands:
      - echo Build started on `date`
      - echo Building the Docker image...
      - docker build -t $REPOSITORY_URI:latest .
      - docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG
  post_build:
    commands:
      - echo Build completed on `date`
      - echo Pushing the Docker images...
      - docker push $REPOSITORY_URI:latest
      - docker push $REPOSITORY_URI:$IMAGE_TAG
      - echo Writing image definitions file...
      - printf '[{"name":"{name}","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
      - cat imagedefinitions.json

artifacts:
  files: imagedefinitions.json

这是我得到的错误:

[Container] 2023/11/15 10:40:59.168094 Running command $(aws ecr get-login-password --region $AWS_DEFAULT_REGION)
/codebuild/output/tmp/script.sh: 4: {long base64 encoded string}: File name too long

[Container] 2023/11/15 10:40:59.876595 Command did not exit successfully $(aws ecr get-login-password --region $AWS_DEFAULT_REGION) exit status 127
[Container] 2023/11/15 10:40:59.879980 Phase complete: PRE_BUILD State: FAILED
[Container] 2023/11/15 10:40:59.879996 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: $(aws ecr get-login-password --region $AWS_DEFAULT_REGION). Reason: exit status 127

解密后的 64 基字符串给出:

{
   "payload":"/{long string that looks randomly generated}",
   "datakey":"{long string but not as long as the previous one}",
   "version":"2",
   "type":"DATA_KEY",
   "expiration":1700088059
}

我已将“AmazonEC2ContainerRegistryFullAccess”和“AmazonEC2ContainerRegistryPowerUser”策略以及默认基本策略附加到与我的构建项目关联的服务角色

我完全迷失了,因为我在互联网上没有找到有关该错误的任何信息,并且 chatgpt 似乎没有帮助

amazon-web-services cicd aws-codebuild amazon-ecr
1个回答
0
投票

你可以尝试删除 $()

- aws ecr get-login-password --region REGION
© www.soinside.com 2019 - 2024. All rights reserved.