Dead Stuck: Jenkins is not able to read the correct path to the Docker

I am following a youtube CICD Pipeline video:
The jenkinsfile is below:

pipeline{
	agent{
        label "jenkins-agent"
    }
    tools {
        jdk 'Java17'
        maven 'Maven3'
        dockerTool 'DOCKER25'
    }
    environment {
        APP_NAME = "complete-prodcution-e2e-pipeline"
        RELEASE = "1.0.0"
        PATH = "C:\\WINDOWS\\SYSTEM32"
        DOCKER_USER = "docker_username"
        DOCKER_PASS = "docker_token"
        IMAGE_NAME = "${DOCKER_USER}" + "/" + "${APP_NAME}"
        IMAGE_TAG = "${RELEASE}-${BUILD_NUMBER}"
    }
    stages{
        stage("Cleanup Workspace"){
            steps {
                cleanWs()
            }

        }

        stage("Checkout from SCM"){
            steps {
                git branch: 'main', credentialsId: 'github', url: 'https://github.com/Coding-s-Life/complete-prodcution-e2e-pipeline'
            }

        }

        stage("Build Application"){
            steps {
                bat 'mvn clean package'
            }
        }

        stage("Test Application"){
            steps {
                bat 'mvn test'
            }
        }

        stage("SonarQube Static Code Analysis"){
            steps {
                script {
                        withSonarQubeEnv(credentialsId: 'jenkins-sonarqube-token') {
                        bat 'mvn sonar:sonar'
                    }
                }
            }
        }

        //stage("SonarQube Quality Gate"){
          //  steps {
            //    script {
              //      waitForQualityGate abortPipeline: false, credentialsId: 'jenkins-sonarqube-token'
               //  }
            // }
        //}
       // stage('Docker login') {
         //   steps {
           //     withCredentials([usernamePassword(credentialsId: 'docker_token', DOCKER_USER: 'DOCKER_USERNAME', DOCKER_PASS: 'DOCKER_PASSWORD')]) {
             //       bat "echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin"
               // }
            //}
        //}
        stage("Build & Push Docker Image") {
            steps {
                script {
                    docker.withRegistry('',DOCKER_PASS) {
                        docker_image = docker.build "${IMAGE_NAME}"
                    }

                    docker.withRegistry('',DOCKER_PASS) {
                        docker_image.push("${IMAGE_TAG}")
                        docker_image.push('latest')
                    }
                }
            }
        }
    }
}

I am trying to configure docker to read my dockerfile and get executed in the docker’s build pipeline. In the Configuration Tools section I have defined


but cannot reach to docker and it gives this following error My actual path in the environment variables in Windows is set as : C:\Program Files\Docker\Docker\resources\bin but this is taking some path always starting from C:\ProgramData\Jenkins.jenkins\tools\hudson, Don’t know why?

$ docker login -u eagertolearn001 -p ******** https://index.docker.io/v1/
exec: "com.docker.cli.exe": executable file not found in %PATH%
Current PATH : C:\ProgramData\Jenkins\.jenkins\tools\hudson.model.JDK\Java17/bin;C:\ProgramData\Jenkins\.jenkins\tools\hudson.tasks.Maven_MavenInstallation\Maven3/bin;C:\ProgramData\Jenkins\.jenkins\tools\hudson.model.JDK\Java17/bin;C:\ProgramData\Jenkins\.jenkins\tools\hudson.tasks.Maven_MavenInstallation\Maven3/bin;C:\WINDOWS\SYSTEM32;C:\Program Files\Jenkins
[Pipeline] // withDockerRegistry

Any help will be greatly appreciated.
Sincere Regards
EagerToLearn

Looks like „C:\Program Files\Docker\Docker\resources\bin“ is not defined in the PATH environment variable.

Is it defined under: Manage Jenkins → Configure System → Global properties → Environment variables ?

1 Like

As you said, now I have defined it like this:

$ docker login -u eagertolearn001 -p ******** https://index.docker.io/v1/
exec: “com.docker.cli.exe”: executable file not found in %PATH%
Current PATH : C:\ProgramData\Jenkins.jenkins\tools\hudson.model.JDK\Java17/bin;C:\ProgramData\Jenkins.jenkins\tools\hudson.tasks.Maven_MavenInstallation\Maven3/bin;C:\Program Files\Docker\Docker\resources\bin/bin;C:\ProgramData\Jenkins.jenkins\tools\hudson.model.JDK\Java17/bin;C:\ProgramData\Jenkins.jenkins\tools\hudson.tasks.Maven_MavenInstallation\Maven3/bin;C:\Program Files\Docker\Docker\resources\bin/bin;C:\WINDOWS\SYSTEM32;C:\Program Files\Jenkins

I am not able to run docker from jenkins pipeline. What should I do?

  • It is showing the path like this: C:\Program Files\Docker\Docker\resources\bin/bin;

  • What should be the configuration in the Manage Jenkins > Tools?

  • What should be the configuration in the Manage Jenkins > System?

Sincere Regards
EagerToLearn

As far as I know, you should only add paths and not files into the PATH environment variable.

It is not clear to me where the second /bin path comes from.
I would look for a corresponding entry with /bin in the configuration and otherwise pragmatically try to adjust the PATH environment variable to “C:\Program Files\Docker\Docker\resources”.

But I am not an expert for Jenkins, so it would be better to ask your question in a forum for Jenkins.

Edit: It is also strange that the path is now displayed incorrectly twice. You may also should check your PATH environment variable in the Windows settings again. Note that the changes should take effect immediately, but sometimes you will need to restart the computer.

1 Like

Great. From the Jenkins Forum I got this resolved by
environment {
PATH = “C:\Program Files\Docker\Docker\resources\bin;${env.PATH}”
// rest of your environment variables…
}

Two related questions:

Successfully tagged docker_username/complete-prodcution-e2e-pipeline:latest
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.

What's Next?
  View a summary of image vulnerabilities and recommendations → docker scout quickview
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withDockerRegistry
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] withEnv
[Pipeline] {
[Pipeline] withDockerRegistry
$ docker login -u eagertolearn001 -p ******** https:  // index .  docker .  io /  v1  /
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Login Succeeded
[Pipeline] {
[Pipeline] isUnix
[Pipeline] withEnv
[Pipeline] {
[Pipeline] bat

C:\ProgramData\Jenkins\.jenkins\workspace\complete-prodcution-e2e-pipeline>docker tag "docker_username/complete-prodcution-e2e-pipeline" "docker_username/complete-prodcution-e2e-pipeline:1.0.0-126" 
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] isUnix
[Pipeline] withEnv
[Pipeline] {
[Pipeline] bat

C:\ProgramData\Jenkins\.jenkins\workspace\complete-prodcution-e2e-pipeline>docker push "docker_username/complete-prodcution-e2e-pipeline:1.0.0-126" 
The push refers to repository [docker.io/docker_username/complete-prodcution-e2e-pipeline]
32bfd2b8ca7a: Preparing
992662809aac: Preparing
47a0b225116f: Preparing
c6813289044b: Preparing
f3a12c51479f: Preparing
b93c1bd012ab: Preparing
b93c1bd012ab: Waiting
denied: requested access to the resource is denied

1. How I can handle this type of an issue:

**SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.**

What should I do?

2. Here below I see that the URL is: https: // index . docker . io / v1 / where as the the actual URL to the hub . docker . com is: Docker
**In Jenkins or in the Dockerfile where I can define this URL?