Reputation: 1813
I am trying to build and push image to docker cloud with Jenkins using the docker-build-step
plugin. Added password for docker hub with Jenkins Password Manager plugin.
I am doing this in two steps. First step uses Build/Create Image
command. The command builds image and tags it with build ID.
Second step pushes image to docker hub. Here is console trace:
[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
Here is complete trace: https://pastebin.com/tFy399D5
Why am I getting Could not push image: denied: requested access to the resource is denied
error for pushing image to Docker Registry, and what can I do to resolve it?
Upvotes: 0
Views: 2646
Reputation: 6703
Had also similar issues as OP, but with the Ram Kamath's code example. The issue lied with the incorrect registryURL that I passed to the docker.withRegistry
. I had it as https://index.docker.io/v2/
but the credentials were for the https://index.docker.io/v1/
API.
Upvotes: 1
Reputation: 1224
Try this
stage('build and publish'){
def dockerImage = docker.build('dockerImageName')
docker.withRegistry(RegistryURL, CredentialID) {
dockerImage.push('latest')
}
}
Upvotes: 0