添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
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

  • $ 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
    

    Also getting this error that jenkins is not able to download the latest docker image when in the “Add installations”, I select docker.com

    Unpacking https://get.docker.com/builds/Windows/x86_64/docker-latest.tgz to C:\ProgramData\Jenkins\.jenkins\tools\org.jenkinsci.plugins.docker.commons.tools.DockerTool\docker on Jenkins
    [Pipeline] // withDockerRegistry
    [Pipeline] }
    [Pipeline] // script
    [Pipeline] }
    [Pipeline] // withEnv
    [Pipeline] }
    [Pipeline] // stage
    [Pipeline] }
    [Pipeline] // withEnv
    [Pipeline] }
    [Pipeline] // withEnv
    [Pipeline] }
    [Pipeline] // node
    [Pipeline] End of Pipeline
    java.io.IOException: Server returned HTTP response code: 403 for URL: https://get.docker.com/builds/Windows/x86_64/docker-latest.tgz
    	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1997)
    	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1589)
    	at java.base/sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:3240)
    	at java.base/java.net.URLConnection.getHeaderFieldLong(URLConnection.java:637)
    	at java.base/java.net.URLConnection.getContentLengthLong(URLConnection.java:509)
    	at java.base/java.net.URLConnection.getContentLength(URLConnection.java:493)
    	at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getContentLength(HttpsURLConnectionImpl.java:368)
    	at org.jvnet.robust_http_client.RetryableHttpStream.<init>(RetryableHttpStream.java:90)
    Caused: java.io.IOException: Server returned HTTP response code: 403 for URL: https://get.docker.com/builds/Windows/x86_64/docker-latest.tgz
    	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
    	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
    	at java.base/sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:2048)
    	at java.base/sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:2043)
    	at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
    	at java.base/sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:2042)
    	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1609)
    	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1589)
    	at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:224)
    	at org.jvnet.robust_http_client.RetryableHttpStream.getStream(RetryableHttpStream.java:98)
    	at org.jvnet.robust_http_client.RetryableHttpStream.<init>(RetryableHttpStream.java:91)
    	at org.jvnet.robust_http_client.RetryableHttpStream.<init>(RetryableHttpStream.java:74)
    	at hudson.ProxyConfiguration.getInputStream(ProxyConfiguration.java:348)
    	at hudson.FilePath.installIfNecessaryFrom(FilePath.java:1068)
    Also:   org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: 0c0fec25-e325-47fb-8ba2-578043be3ba8
    Caused: java.io.IOException: Failed to install https://get.docker.com/builds/Windows/x86_64/docker-latest.tgz to C:\ProgramData\Jenkins\.jenkins\tools\org.jenkinsci.plugins.docker.commons.tools.DockerTool\docker
    	at hudson.FilePath.installIfNecessaryFrom(FilePath.java:1086)
    	at hudson.FilePath.installIfNecessaryFrom(FilePath.java:981)
    	at org.jenkinsci.plugins.docker.commons.tools.DockerToolInstaller.performInstallation(DockerToolInstaller.java:135)
    	at hudson.tools.InstallerTranslator.getToolHome(InstallerTranslator.java:70)
    	at hudson.tools.ToolLocationNodeProperty.getToolHome(ToolLocationNodeProperty.java:109)
    	at hudson.tools.ToolInstallation.translateFor(ToolInstallation.java:221)
    	at org.jenkinsci.plugins.docker.commons.tools.DockerTool.forNode(DockerTool.java:106)
    	at org.jenkinsci.plugins.docker.commons.tools.DockerTool.getExecutable(DockerTool.java:80)
    	at org.jenkinsci.plugins.docker.workflow.RegistryEndpointStep$Execution2.newKeyMaterialFactory(RegistryEndpointStep.java:96)
    	at org.jenkinsci.plugins.docker.workflow.AbstractEndpointStepExecution2.doStart(AbstractEndpointStepExecution2.java:52)
    	at org.jenkinsci.plugins.workflow.steps.GeneralNonBlockingStepExecution.lambda$run$0(GeneralNonBlockingStepExecution.java:77)
    	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    	at java.base/java.lang.Thread.run(Thread.java:842)
    Finished: FAILURE
    

    Any help will be greatly appreciated.
    Sincere Regards
    EagerToLearn

    Hello @eagertolearn and welcome to this community. :wave:

    It looks like the docker executable cannot be found in PATH.
    The error exec: "com.docker.cli.exe": executable file not found in %PATH% suggests that Jenkins is not able to find the Docker executable. :person_shrugging:
    This could be because the docker executable is not in the PATH that Jenkins is using. You could try adding the docker executable path to the PATH environment variable in your Jenkinsfile:

    environment {
        PATH = "C:\\Program Files\\Docker\\Docker\\resources\\bin;${env.PATH}"
        // rest of your environment variables...
                  

    Great, 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. 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?

    2. 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?

    APP_NAME = "complete-prodcution-e2e-pipeline" RELEASE = "1.0.0" PATH = "C:\\WINDOWS\\SYSTEM32;C:\\WINDOWS\\SYSTEM32;C:\\Program Files\\Docker\\Docker\\resources\\bin;${env.PATH}" DOCKER_REGISTRY = 'https://hub.docker.com/repository/docker' DOCKER_USER = "eagertolearn001" DOCKER_PASS = 'dockerhub' IMAGE_NAME = "${DOCKER_USER}/${APP_NAME}" BUILD_NUMBER = "700" 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("Maven Validate") { steps { bat 'mvn validate' stage("Maven Compile") { steps { bat 'mvn compile' stage("Maven Test") { steps { bat 'mvn test' stage("Maven Package") { steps { bat 'mvn package' stage("Test Install") { steps { bat 'mvn install -Dmaven.install.directory=target' stage("SonarQube Static Code Analysis") { steps { script { withSonarQubeEnv(credentialsId: 'jenkins-sonarqube-token') { bat 'mvn sonar:sonar' stage("Build Docker Image") { steps { withCredentials([usernamePassword(credentialsId: 'docker_token', toolName: 'docker', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) { script { withDockerRegistry(credentialsId: 'docker_token', toolName: 'docker') { bat "docker build -t ${APP_NAME} -f Dockerfile ." stage("TAG Docker Image"){ steps{ withCredentials([usernamePassword(credentialsId: 'docker_token', toolName: 'docker', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) { script { withDockerRegistry(credentialsId: 'docker_token', toolName: 'docker') { bat "docker tag ${APP_NAME} ${IMAGE_NAME}:${IMAGE_TAG}" stage("PUSH Docker Image") { steps { withCredentials([usernamePassword(credentialsId: 'docker_token', toolName: 'docker', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]) { script { withDockerRegistry(credentialsId: 'docker_token', toolName: 'docker') { bat "docker push ${IMAGE_NAME}:${IMAGE_TAG}" stage("DEPLOY to Docker Container To Run Application"){ steps { withCredentials([usernamePassword(credentialsId: 'docker_token', toolName: 'docker', usernameVariable: 'DOCKER_USER', passwordVariable: 'DOCKER_PASS')]){ script { withDockerRegistry(credentialsId: 'docker_token', toolName: 'docker') { bat "docker rm demoapp1" bat "docker run -d --name demoapp1 -p 8098:8098 ${IMAGE_NAME}:${IMAGE_TAG}"