amazon-web-services - Jenkins ECR - 无法运行程序“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 build 命令通过,但后来 docker push 命令失败,找不到“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')
}
}
推荐阅读
- node.js - node npm run watch 退出状态 3221225725
- css - 在css中实现表格的最简洁方法,哪一列没有显式宽度(但包装内容),而其他列具有固定宽度?
- java - 为什么这个类是可变的?
- php - 创建子母公司 Laravel 的无限嵌套层次数组
- android - 如何在房间数据库中加入多个表
- mongodb - 您如何在 mongoose 的关联模式上对 2 个字段进行分组?
- angular - 如何在 Angular 中测试离子 Web 组件
- java - 堆栈溢出错误是否被视为内存泄漏错误?
- c# - 如何使uwp弹出全屏
- python-3.x - 如何在 Django 模型中的 C 结构中存储值