从这个论坛上的优秀人员,我能够以编程方式获取图像ID,如Why doesn't the cut command work for a “docker image ls” command?中所述。那么下一个问题。
我现在在Jenkins文件的一个阶段中有这个。它的目的是执行docker save命令将图像保存在tar球中并将其上传到S3存储桶。
stage("Cache ECS Image") {
image = sh(returnStdout: true, script: "docker image ls | grep ${env.DBName} | tr -s \" \" | cut -d \" \" -f3").trim()
echo "Image ID: $image"
if (image?.trim()) {
save_rc = sh(returnStatus: true, script: "docker save -o /tmp/${dockerCache} ${image}")
echo "save_rc: $save_rc"
if (save_rc == 0) {
zip_rc = sh(returnStatus: true, script: "gzip /tmp/${dockerCache}")
echo "zip_rc: $zip_rc"
if (zip_rc == 0) {
s3Upload(file: "/tmp/${dockerCache}.gz", bucket: "zift-infrastructure", path: "docker-cache")
}
}
}
}
回显图像ID的语句显示正确的图像ID
18:10:35 Image ID: 880e071dff55
但是docker save语句给出了
18:10:36 + docker save -o /tmp/zift-prm-sandbox-prmchrisf.tar 880e071dff55
18:13:42 + 880e071dff55
18:13:42 /home/jenkins/workspace/PRM - ChrisF Pipeline@tmp/durable-6e24b672/script.sh: 3: /home/jenkins/workspace/PRM - ChrisF
Pipeline@tmp/durable-6e24b672/script.sh: 880e071dff55: not found
[Pipeline] echo
18:13:42 save_rc: 127
为什么docker save命令失败,显然图像在节点上?