我无法使用Jenkins Pipeline将ocker图像推送到Amazon ECR:我总是得到no basic auth credentials
: - (
这是我的设置:
aws-jenkins
添加到Jenkins(在本地测试并成功推送到AWS ECR)/root/.dockercfg
Jenkinsfile
来调试身份验证
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()
}
}
日志:
[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
有什么想法吗?
更新(2017-05-23):
这是Jira问题:
https://issues.jenkins-ci.org/browse/JENKINS-44143
答案 0 :(得分:1)
即使这样看起来合乎逻辑的是,docker.withRegistry将在启动时执行对ECR的登录并在完成时注销,但它不会执行。 因此,在执行推送之前,您必须安装 awscli 并添加ECR登录命令。
sh(“eval \ $(aws ecr get-login --no-include-email | sed's | https://||')”)
答案 1 :(得分:0)
只需从本地PC或云服务器中删除或重命名 $ HOME / .docker / config.json 文件即可。它将解决 没有基本身份验证凭据 的问题。
在您的终端中执行以下步骤:
mv $HOME/.docker/config.json $HOME/.docker/config.json.backup