简体   繁体   English

Jenkins Amazon ECR:没有基本的身份验证凭据

[英]Jenkins Amazon ECR: no basic auth credentials

I'm not able to push ocker images to Amazon ECR with Jenkins Pipeline: I always get no basic auth credentials :-(我无法使用 Jenkins 管道将 ocker 图像推送到 Amazon ECR:我总是得不到no basic auth credentials :-(

Here is my setup:这是我的设置:

  • Jenkins 2.46.2詹金斯 2.46.2
  • Amazon ECR plugin 1.4亚马逊 ECR 插件 1.4
  • I've added AWS credentials aws-jenkins to Jenkins (tested locally and successfully pushed to AWS ECR)我已将 AWS 凭据aws-jenkins添加到 Jenkins(在本地测试并成功推送到 AWS ECR)
  • I've printed /root/.dockercfg to debug auth in my Jenkinsfile我打印/root/.dockercfg以在我的Jenkinsfile中调试 auth

Jenkinsfile:詹金斯文件:

stage("Docker") {
  dir(path) {
    docker.build("my-image:latest")
  }
  docker.withRegistry("https://<my-aws-id>.dkr.ecr.eu-central-1.amazonaws.com", "ecr:eu-central-1:aws-jenkins") {
    sh "cat /root/.dockercfg" // debug
    docker.image("my-image:latest").push()
  }
}

Logs:日志:

[Pipeline] withDockerRegistry
Wrote authentication to /root/.dockercfg
[Pipeline] {
[Pipeline] sh
[docker-emotion-compilers] Running shell script
+ cat /root/.dockercfg
{"https://<my-aws-id>.dkr.ecr.eu-central-1.amazonaws.com": {
  "auth": "[...]",
  "email": "nobody@example.com"
}}[Pipeline] sh
[docker-emotion-compilers] Running shell script
+ docker tag --force=true my-image:latest <my-aws-id>.dkr.ecr.eu-central-1.amazonaws.com/my-image:latest
Warning: '--force' is deprecated, it will be removed soon. See usage.
[Pipeline] sh
[docker-emotion-compilers] Running shell script
+ docker push <my-aws-id>.dkr.ecr.eu-central-1.amazonaws.com/my-image:latest
The push refers to a repository [<my-aws-id>.dkr.ecr.eu-central-1.amazonaws.com/my-image]
e30bf54e0f87: Preparing
b9f2c30c0d28: Preparing
5defc95691fd: Preparing
295d6a056bfd: Preparing
no basic auth credentials
[Pipeline] }
[Pipeline] // withDockerRegistry

Any ideas?有任何想法吗?

UPDATE (2017-05-23):更新(2017-05-23):
Here is the Jira issue: https://issues.jenkins-ci.org/browse/JENKINS-44143这是 Jira 问题: https ://issues.jenkins-ci.org/browse/JENKINS-44143

Even that it seems logical that docker.withRegistry will perform a login to ECR at start and logout when done, it is not performed.即使 docker.withRegistry 将在开始时执行登录到 ECR 并在完成后注销看起来合乎逻辑,它也不会执行。 Therefor you must install awscli and add ECR login command before you perform the push.因此,您必须在执行推送之前安装awscli并添加 ECR 登录命令。

sh("eval \$(aws ecr get-login --no-include-email | sed 's| https://|| ')") sh("eval \$(aws ecr get-login --no-include-email | sed 's| https://|| ')")

See http://www.tikalk.com/devops/ecr-in-pipeline/ for detailed example.有关详细示例,请参阅http://www.tikalk.com/devops/ecr-in-pipeline/

just remove or rename $HOME/.docker/config.json file from your local pc or cloud server.只需从本地 pc 或云服务器中删除或重命名$HOME/.docker/config.json文件。 It will solve the no basic auth credentials issue.它将解决没有基本身份验证凭据的问题。

Follow the below step in your terminal:在您的终端中执行以下步骤:

mv $HOME/.docker/config.json $HOME/.docker/config.json.backup

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AWS ECR 的 Api 凭证 - Api credentials for AWS ECR AWS CodePipeline Docker 推送命令返回“无基本身份验证凭证” - AWS CodePipeline Docker push command returns 'no basic auth credentials' 如何将Docker镜像推送到Jenkins中的ECR? - How to push Docker image to ECR in Jenkins? 如何列出公共亚马逊 ecr 回购中可用的图像? - how to list images available in a public amazon ecr repo? 如何在 Sagemaker 中获取特定 model 图像的 Amazon ECR 容器 URI? - How to get an Amazon ECR container URI for a specific model image in Sagemaker? 在没有 AWS 凭据的情况下从 AWS ECR 存储库中提取图像 - Pulling image from AWS ECR repository without AWS credentials 关于在Jenkins配置上传docker图片到ECR的问题 - Question about configuring policy for uploading docker image to ECR in Jenkins 在 Jenkinsfile 中对 ECR 进行授权,以便我可以提取图像来运行构建? - Auth into ECR in a Jenkinsfile so I can pull an image to run the build in? 反应 NextAuth 凭据 null 和 Auth 不工作 - React NextAuth credentials null and Auth Not Working ECS unable to pull secrets or registry auth,与 api.ecr 端点相关,Resourceinitializationerror - ECS unable to pull secrets or registry auth, related to the api.ecr endpoint, Resourceinitializationerror
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM