Push Docker Repository to Dockerhub with Jenkins Push Docker Repository to Dockerhub with Jenkins jenkins jenkins

Push Docker Repository to Dockerhub with Jenkins


Can you have a try with the CloudBees Docker Build and Publish plugin?

This plugin allows to create a build step to build a Dockerfile and publish the image into a registry (DockerHub or a private registry):

enter image description here

Another solution is to open a session on your Jenkins machine with the jenkins user + login to DockerHub with the relevant credentials?

With this solution, the DockerHub credentials will be cached and Jenkins should be able to push your images to the DockerHub registry.


Maybe you can use Docker pipeline plugin (it comes in the recommended plugins).

Jenkinsfile example:

node {  checkout scm  def dockerImage  stage('Build image') {    dockerImage = docker.build("username/repository:tag")  }  stage('Push image') {    dockerImage.push()  }   }

Doing it this way, you must specify the credentials of the docker registry in the Pipeline Model Definition.

Docker pipeline plugin has problems applying the credentials assigned in Pipeline Model Definition to projects with Multi-branch pipeline. That is, if using the above code you continue to receive the error:

denied: requested access to the resource is denied

Then you must specify the credentials in the Jenkinsfile as follows:

node {  checkout scm  def dockerImage  stage('Build image') {    dockerImage = docker.build("username/repository:tag")  }  stage('Push image') {    docker.withRegistry('https://registry-1.docker.io/v2/', 'docker-hub-credentials') {      dockerImage.push()    }  }}

You can modify the URL to a custom registry if you need it