0

I'm trying to build my Maven project with Jenkins and Docker.

I prepared following Jenkinsfile inside my repository.

pipeline { agent none stages { stage('3-jdk-8') { agent { docker { registryUrl 'https://registry.hub.docker.com' registryCredentialsId 'docker-hub' image 'maven:3-jdk-8' args '-v $HOME/.m2:/root/.m2' reuseNode true } } steps { sh 'mvnw -B clean build' } } stage('3-jdk-11') { agent { docker { registryUrl 'https://registry.hub.docker.com' registryCredentialsId 'docker-hub' image 'maven:3-jdk-11' args '-v $HOME/.m2:/root/.m2' reuseNode true } } steps { sh 'mvnw -B clean build' } } } } 

When I trigger the item, I got this.

Started by user Jin Kwon Checking out git https://....git into /var/lib/jenkins/workspace/...@script to read Jenkinsfile Selected Git installation does not exist. Using Default The recommended git tool is: NONE using credential ... > git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/...@script/.git # timeout=10 Fetching changes from the remote Git repository > git config remote.origin.url https://....git # timeout=10 Fetching upstream changes from https://....git > git --version # timeout=10 > git --version # 'git version 2.25.1' using GIT_ASKPASS to set credentials > git fetch --tags --force --progress -- https://....git +refs/heads/*:refs/remotes/origin/* # timeout=10 > git rev-parse origin/develop^{commit} # timeout=10 Checking out Revision c9627132515a20c209a6e0d5f14c3779fa1eb933 (origin/develop) > git config core.sparsecheckout # timeout=10 > git checkout -f c9627132515a20c209a6e0d5f14c3779fa1eb933 # timeout=10 Commit message: "Configure docker.registry(Url|registryCredentialId)" > git rev-list --no-walk c9627132515a20c209a6e0d5f14c3779fa1eb933 # timeout=10 [Pipeline] Start of Pipeline [Pipeline] stage [Pipeline] { (3-jdk-8) [Pipeline] getContext [Pipeline] node Running on Jenkins in /var/lib/jenkins/workspace/... [Pipeline] { [Pipeline] checkout Selected Git installation does not exist. Using Default The recommended git tool is: NONE using credential ... > git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/.../.git # timeout=10 Fetching changes from the remote Git repository > git config remote.origin.url https://....git # timeout=10 Fetching upstream changes from https://....git > git --version # timeout=10 > git --version # 'git version 2.25.1' using GIT_ASKPASS to set credentials > git fetch --tags --force --progress -- https://....git +refs/heads/*:refs/remotes/origin/* # timeout=10 > git rev-parse origin/develop^{commit} # timeout=10 Checking out Revision c9627132515a20c209a6e0d5f14c3779fa1eb933 (origin/develop) > git config core.sparsecheckout # timeout=10 > git checkout -f c9627132515a20c209a6e0d5f14c3779fa1eb933 # timeout=10 Commit message: "Configure docker.registry(Url|registryCredentialId)" [Pipeline] withEnv [Pipeline] { [Pipeline] withEnv [Pipeline] { [Pipeline] withDockerRegistry Using the existing docker config file.Removing blacklisted property: auths$ docker login -u onacit -p ******** https://registry.hub.docker.com WARNING! Using --password via the CLI is insecure. Use --password-stdin. WARNING! Your password will be stored unencrypted in /var/lib/jenkins/workspace/...@tmp/950e743c-139b-4e14-93c3-b9fda206b1f4/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded [Pipeline] { [Pipeline] withEnv [Pipeline] { [Pipeline] isUnix [Pipeline] sh + docker inspect -f . maven:3-jdk-8 Error: No such object: maven:3-jdk-8 [Pipeline] isUnix [Pipeline] sh + docker inspect -f . registry.hub.docker.com/maven:3-jdk-8 Error: No such object: registry.hub.docker.com/maven:3-jdk-8 [Pipeline] withEnv [Pipeline] { [Pipeline] isUnix [Pipeline] sh + docker pull registry.hub.docker.com/maven:3-jdk-8 Error response from daemon: unauthorized: authentication required [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // withDockerRegistry [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // withEnv [Pipeline] } [Pipeline] // node [Pipeline] } [Pipeline] // stage [Pipeline] stage [Pipeline] { (3-jdk-11) Stage "3-jdk-11" skipped due to earlier failure(s) [Pipeline] } [Pipeline] // stage [Pipeline] End of Pipeline ERROR: script returned exit code 1 Finished: FAILURE 

1 Answer 1

2

Jenkins (Docker Daemon) cannot find the image. Or in other words cannot find the registry.

+ docker pull registry.hub.docker.com/maven:3-jdk-8 Error response from daemon: unauthorized: authentication required 

You just need to modify the registry URL in the config with docker.io like this.

 stage('3-jdk-8') { agent { docker { registryUrl 'https://docker.io' registryCredentialsId 'docker-hub' image 'maven:3-jdk-8' args '-v $HOME/.m2:/root/.m2' reuseNode true } } 

Or you can omit the registryUrl and registryCredentialsId since the maven image is in the public registry (Docker Hub). And Jenkins will try to pull it from there by default.

 stage('3-jdk-8') { agent { docker { image 'maven:3-jdk-8' args '-v $HOME/.m2:/root/.m2' reuseNode true } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.