我想使用Jenkins Docker管道插件在Docker Hub上提取具有特定标记的特定私有映像的新版本。 Docker shell命令看起来像:
docker login -u user -p password
docker pull user/foo:bar
像这样的东西似乎应该工作:
node () {
image = docker.image('user/foo:bar')
image.pull()
image.inside {
// Commands to run in the container
但是没有办法执行登录步骤,所以我总是得到错误:
Error response from daemon: pull access denied for user/foo, repository does not exist or may require 'docker login'.
我已经浏览了documentation和code,但文档甚至没有提到拉动,代码中的示例没有显示如何登录以拉出私有图像。我可以手动编写脚本,但使用Docker管道插件的全部目的是避免直接编写Docker命令脚本。
我相信你需要的是withRegistry
功能。它可以如下使用
docker.withRegistry('<registry-url>', '<credential-id>') {
image = docker.image('user/foo:bar')
image.pull()
}
withRegistry
块中的所有内容都将使用该注册表和身份验证来提取图像。
这种情况下<registry-url>
是Dockerhub注册表的URL。我相信Dockerhub注册表URL是https://registry.hub.docker.com
<credential-id>
是存储在Jenkins中的Dockerhub凭证的ID。
要添加这些凭据,请从Jenkins索引页面导航到Credentials -> System -> Global credentials -> Add Credentials
。
进入此页面后,您需要选择Kind
作为Username with password
。范围应该是Global
。 username
和password
字段是Dockerhub的用户名和密码。
ID
字段是你想成为<credential-id>
的任何文本。例如,如果你使ID
字段docker-hub-credentials
需要成为withRegistry
的第二个参数。