Issue
So I'm trying to set up a pipeline in Jenkins to build image and push them to Docker hub. My credentials in Manage 'Jenkins' are called the same as "docker-hub-credentials" and seem to be used.
It can build, but it just doesn't get through the push... Help? I've been on that for hours and I'm not sure what I' missing.
I've already tried using docker login, but jenkins doesn't allow it.
stage('Build image') {
/* This builds the actual image; synonymous to
* docker build on the command line */
bat 'docker build -t username/foldername:build . ' }
stage('Push image') {
/* Finally, we'll push the image with two tags:
docker.withRegistry('https://registry.hub.docker.com', 'docker-hub-credentials') {
bat 'docker push username/foldername:build'
}
}
I expect the image to be pushed, but I have this instead :
The push refers to repository [docker.io/username/foldername]
a73d7d9f4346: Preparing
964bdfb24a54: Preparing
1af124d739c9: Preparing
6cffeea81e5d: Preparing
614a79865f6d: Preparing
612d27bb923f: Preparing
ef68f6734aa4: Preparing
612d27bb923f: Waiting
ef68f6734aa4: Waiting
denied: requested access to the resource is denied
Solution
I found the answer!!!
stage('Push image') {
withDockerRegistry([ credentialsId: "docker-hub-credentials", url: "" ]) {
bat "docker push devopsglobalmedia/teamcitydocker:build"
}
Answered By - shrimpy
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)