簡體   English   中英

Jenkins ECR - 無法運行程序“docker”

[英]Jenkins ECR - Cannot run program “docker”

我有以下 Jenkinsfile 管道

pipeline {
agent { label 'master' }
environment {
    def dockerHome = tool 'myDocker'
    PATH = "${dockerHome}/bin:${env.PATH}"
}
stages {
    stage('Checkout') {
        steps {
            checkout scm
        }
    }
    stage('Build docker image') {
        steps {
            script {
                docker.build('rgs')
            }
        }
    }
    stage('Push image to ECR') {
        steps {
            script {
                docker.withRegistry('https://316482606904.dkr.ecr.eu-central-1.amazonaws.com', 'ecr:eu-central-1:aws') {
                    docker.image('rgs').push('latest')
                }
            }
        }
    }
}

Jenkins 服務器使用 EC2 容器在 ECS 上運行。 我有 Docker 工具安裝 + AWS ecr 插件。

管道失敗並顯示以下日志:

Started by user Amitai Mazliah
Replayed #66
Obtained Jenkinsfile from fc49bec66b631c9cb7c7966f4612fddae5dc9954
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/jenkins_home/workspace/rgs_feature_test-pipeline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
...
[Bitbucket] Notifying commit build result
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] tool
[Pipeline] tool
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Checkout)
[Pipeline] checkout
The recommended git tool is: NONE
using credential bitbucket-cloud
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://bitbucket.org/{2150147d-c2e4-48c1-9921-fca23276a0d3}/rgs.git # timeout=10
Cleaning workspace
 > git rev-parse --verify HEAD # timeout=10
Resetting working tree
 > git reset --hard # timeout=10
 > git clean -fdx # timeout=10
Fetching without tags
Fetching upstream changes from https://bitbucket.org/{2150147d-c2e4-48c1-9921-fca23276a0d3}/rgs.git
 > git --version # timeout=10
 > git --version # 'git version 2.20.1'
using GIT_ASKPASS to set credentials Bitbucket server credentials
 > git fetch --no-tags --force --progress -- https://bitbucket.org/{2150147d-c2e4-48c1-9921-fca23276a0d3}/rgs.git +refs/heads/feature/test-pipeline:refs/remotes/origin/feature/test-pipeline # timeout=10
Checking out Revision fc49bec66b631c9cb7c7966f4612fddae5dc9954 (feature/test-pipeline)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f fc49bec66b631c9cb7c7966f4612fddae5dc9954 # timeout=10
 > git branch -a -v --no-abbrev # timeout=10
 > git branch -D feature/test-pipeline # timeout=10
 > git checkout -b feature/test-pipeline fc49bec66b631c9cb7c7966f4612fddae5dc9954 # timeout=10
Commit message: "#2"
Cleaning workspace
 > git rev-parse --verify HEAD # timeout=10
Resetting working tree
 > git reset --hard # timeout=10
 > git clean -fdx # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build docker image)
[Pipeline] script
[Pipeline] {
[Pipeline] isUnix
[Pipeline] sh
+ docker build -t rgs .
Sending build context to Docker daemon   1.99MB
...
Successfully built 770950512188
Successfully tagged rgs:latest
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Push image to ECR)
[Pipeline] script
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] withDockerRegistry
$ docker login -u AWS -p ******** https://**********.dkr.ecr.eu-central-1.amazonaws.com
[Pipeline] // withDockerRegistry
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
[Bitbucket] Notifying commit build result
[Bitbucket] Build result notified
java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
    at java.lang.ProcessImpl.start(ProcessImpl.java:134)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
Caused: java.io.IOException: Cannot run program "docker": error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at hudson.Proc$LocalProc.<init>(Proc.java:252)
    at hudson.Proc$LocalProc.<init>(Proc.java:221)
    at hudson.Launcher$LocalLauncher.launch(Launcher.java:996)
    at hudson.Launcher$ProcStarter.start(Launcher.java:508)
    at hudson.Launcher$ProcStarter.join(Launcher.java:519)
    at org.jenkinsci.plugins.docker.commons.impl.RegistryKeyMaterialFactory.materialize(RegistryKeyMaterialFactory.java:101)
    at org.jenkinsci.plugins.docker.workflow.AbstractEndpointStepExecution2.doStart(AbstractEndpointStepExecution2.java:53)
    at org.jenkinsci.plugins.workflow.steps.GeneralNonBlockingStepExecution.lambda$run$0(GeneralNonBlockingStepExecution.java:77)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE

現在,我覺得奇怪的是 docker 構建命令通過,但后來 docker 推送命令失敗,找不到“docker”

我錯過了什么?

提前致謝

添加 docker.withTool。 它應該工作!

docker.withTool(<DockerInstallerName>){
  docker.withRegistry('https://316482606904.dkr.ecr.eu-central-1.amazonaws.com', 'ecr:eu-central-1:aws') {
                docker.image('rgs').push('latest')
            }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM