Jenkins docker-build-step插件无法将图像推送到docker cloud

时间:2017-11-22 13:00:33

标签: docker jenkins jenkins-plugins jenkins-pipeline continuous-deployment

我正在尝试使用docker-build-step插件使用Jenkins构建并将映像推送到docker cloud。使用Jenkins Password Manager插件为docker hub添加了密码。

我分两步完成这项工作。第一步使用Build/Create Image命令。该命令构建映像并使用构建ID对其进行标记。

第二步将图像推送到docker hub。这是控制台跟踪:

[Docker] INFO: Build image id:5240329f9db6
[Docker] INFO: Pushing image parthmodi/docker_demo:test_push
[Docker] INFO: PushResponseItem[stream=<null>,status=The push refers to a repository [docker.io/parthmodi/docker_demo],progressDetail=<null>,progress=<null>,id=<null>,from=<null>,time=<null>,errorDetail=<null>,error=<null>,aux=<null>]

...

[Docker] INFO: PushResponseItem[stream=<null>,status=<null>,progressDetail=<null>,progress=<null>,id=<null>,from=<null>,time=<null>,errorDetail=ResponseItem.ErrorDetail[code=<null>,message=denied: requested access to the resource is denied],error=denied: requested access to the resource is denied,aux=<null>]
ERROR: Build step failed with exception
com.github.dockerjava.api.exception.DockerClientException: Could not push image: denied: requested access to the resource is denied
    at com.github.dockerjava.core.command.PushImageResultCallback.awaitSuccess(PushImageResultCallback.java:49)
    at org.jenkinsci.plugins.dockerbuildstep.cmd.PushImageCommand.execute(PushImageCommand.java:81)
    at org.jenkinsci.plugins.dockerbuildstep.DockerBuilder.perform(DockerBuilder.java:74)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:736)
    at hudson.model.Build$BuildExecution.build(Build.java:206)
    at hudson.model.Build$BuildExecution.doRun(Build.java:163)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:496)
    at hudson.model.Run.execute(Run.java:1737)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:421)
Build step 'Execute Docker command' marked build as failure
Finished: FAILURE

这是完整的跟踪: https://pastebin.com/tFy399D5

为什么我将图像推送到Docker Registry会出现Could not push image: denied: requested access to the resource is denied错误,我该怎么办才能解决它?

2 个答案:

答案 0 :(得分:0)

试试这个

stage('build and publish'){
def dockerImage = docker.build('dockerImageName')
docker.withRegistry(RegistryURL, CredentialID) {
       dockerImage.push('latest')
}
}

答案 1 :(得分:0)

还有与OP类似的问题,但是使用了Ram Kamath的代码示例。问题与我传递给docker.withRegistry的不正确的registryURL有关。我将其作为https://index.docker.io/v2/,但凭据是https://index.docker.io/v1/ API。