通过查阅官方文档和支持社区,找到以下解决办法:
version: 0.2
phases: install: runtime-versions: java: corretto11 docker: 18
pre_build: commands: - echo Logging in to Amazon ECR... - aws --version - $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email) - IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION) - IMAGE_URI=$REPOSITORY_URI:$IMAGE_TAG - echo $IMAGE_URI
build:
commands:
- echo Build started on date
- echo Building the Docker image...
- docker build -t $IMAGE_URI .
- docker tag $IMAGE_URI $REPOSITORY_URI:latest
post_build:
commands:
- echo Build completed on date
- echo Pushing the Docker images...
- docker push $REPOSITORY_URI:$IMAGE_TAG
- docker push $REPOSITORY_URI:latest
- aws elasticbeanstalk create-application-version --application-name $APP_NAME --version-label $IMAGE_TAG --description "Created by AWS CodeBuild" --source-bundle S3Bucket=$BUCKET,S3Key=$ZIP_FILE
- aws elasticbeanstalk update-environment --environment-name $ENV_NAME --version-label $IMAGE_TAG
aws --version
运行以下命令登录CLI:
aws configure
export AWS_CODEBUILD_BUILD_IMAGE="aws/codebuild/amazonlinux2-x86_64-standard:3.0"