Jenkins docker push to harbor to report error

Jenkins docker push to harbor private service error solution

Jenkins reported an error

When using docker push to private service in jenkinsfile, an error is reported. The error information is as follows:

unauthorized: unauthorized to access repository: ocp/eureka-server, action: push: unauthorized to access repository: ocp/eureka-server, action: push

This is because Jenkins uses the pseudo user of Jenkins when pushing the image. Since you need to log in to push, you should first generate config.json in the current user

The current user uses docker login to generate config.json

The current user logs in with the following command

docker login ip:port

After entering the user name and you, a config.json file is generated in the. Docker directory of the current user’s root directory, as follows:

[[email protected] ~]$ cat /root/.docker/config.json 
{
        "auths": {
                "harbor.aiuyo.com:643": {
                        "auth": "d2FuZ3hpYW5mZW5nOlhpYW5mZW5nOTk="
                }
        }
}

Copy. Docker to/var/lib/Jenkins directory

    after logging in with root, copy the/user name /. Docker/directory to/var/lib/Jenkins, and modify the folder permission chown – R Jenkins. Jenkins. Docker to/var/lib/Jenkins

     

    cp -r /root/.docker/ /var/lib/jenkins/
    cd /var/lib/jenkins/
    chown -R jenkins.jenkins .docker

    I am for this reason. After modification, it can be pushed


Read More: