【以下的问题经过翻译处理】 我正在使用AWS CodePipeline准备CI/CD流程。不幸的是,在构建阶段中出现了错误。以下是我的buildspec.yml文件的内容,其中:
AWS_DEFAULT_REGION = eu-central-1
CONTAINER_NAME=cicd-1-app
REPOSITORY_URI = <ACCOUNT_ID>.dkr.ecr.eu-central-1.amazonaws.com/cicd-1-app
version: 0.2
phases:
install:
runtime-versions:
java: corretto11
pre_build:
commands:
- echo Logging in to Amazon ECR...
- aws --version
- TAG="$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | head -c 8)"
- IMAGE_URI=${REPOSITORY_URI}:${TAG}
build:
commands:
- echo Build started on `date`
- echo $IMAGE_URI
- mvn clean package -Ddockerfile.skip
- docker build --tag $IMAGE_URI .
post_build:
commands:
- printenv
- echo Build completed on `date`
- echo $(docker images)
- echo Pushing docker image
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin <ACCOUNT_ID>.dkr.ecr.eu-central-1.amazonaws.com
- docker push $IMAGE_URI
- echo push completed
- printf '[{"name":"%s","imageUri":"%s"}]' $CONTAINER_NAME $IMAGE_URI > imagedefinitions.json
artifacts:
files:
- imagedefinitions.json
我收到错误:
[Container] 2022/01/06 19:57:36 Running command aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin <ACCOUNT_ID>.dkr.ecr.eu-central-1.amazonaws.com
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
[Container] 2022/01/06 19:57:37 Running command docker push $IMAGE_URI
The push refers to repository [<ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/cicd-1-app]
37256fb2fd27: Preparing
fe6c1ddaab26: Preparing
d4dfab969171: Preparing
no basic auth credentials
[Container] 2022/01/06 19:57:37 Command did not exit successfully docker push $IMAGE_URI exit status 1
[Container] 2022/01/06 19:57:37 Phase complete: POST_BUILD State: FAILED
[Container] 2022/01/06 19:57:37 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: docker push $IMAGE_URI. Reason: exit status 1
即使Docker成功登录,仍然出现“no basic auth credentials”错误。你知道可能出了什么问题吗?
此致。