Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-75948

docker.withRegistry does not work with tool "docker"

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • docker
    • None

      docker.withRegistry ignores PATH set by tool "docker" and so can not find "docker" binary.

      pipeline {
          agent { ... }
      
          tools { dockerTool 'docker' }
      
          stages {
              stage('test'){
                  steps {
                      script {
                          sh '''
                              : "PATH=$PATH"
                              which docker || true
                              docker --version || true
                          '''
      
                          docker.withRegistry('http://nexus.local:5000', 'nexus'){
                              sh ': "PATH=$PATH"'
      
                              //docker.image('...').push()
                          }
                      }
                  }
              }
          }
      }
      

      Console output:

      Unpacking https://download.docker.com/linux/static/stable/x86_64/docker-28.3.3.tgz to /home/user/tools/org.jenkinsci.plugins.docker.commons.tools.DockerTool/docker on minimal-0044l59lofet8 on jenkins-agent0.env.geomotiv.com
      .....
      [Pipeline] sh
      + : PATH=/home/user/tools/org.jenkinsci.plugins.docker.commons.tools.DockerTool/docker/bin:/home/user/tools/org.jenkinsci.plugins.docker.commons.tools.DockerTool/docker/bin:/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
      + which docker
      /home/user/tools/org.jenkinsci.plugins.docker.commons.tools.DockerTool/docker/bin/docker
      + docker --version
      Docker version 28.3.3, build 980b856
      .....
      [Pipeline] withDockerRegistry
      $ docker login -u jenkins -p ******** http://nexus.local:5000
      [Pipeline] // withDockerRegistry
      .....
      [Pipeline] End of Pipeline
      java.io.IOException: error=2, No such file or directory
      .....
      Also:   org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: d905b84a-21ca-4322-bfbb-19fa05e5f7be
      Caused: java.io.IOException: Cannot run program "docker": error=2, No such file or directory
      Finished: FAILURE
      

            csanchez Carlos Sanchez
            spirit Sergei
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: