GitLab CI中Docker镜像内rsync仅部分同步失败问题
GitLab CI Docker环境下第二次rsync同步报错排查问题
环境:Ubuntu 22 LTS系统,Docker 28.0.4版本(构建号b8034c0),已制作好可用镜像。当前在GitLab CI中执行两次rsync同步任务:
- 第一次:将/local-one/同步到user@server.com:/remote-one(始终成功)
- 第二次:将/local-two/同步到user@server.com:/remote-two(仅在GitLab CI环境报错,本地手动执行无问题)
成功的rsync命令
rsync -avz --delete --exclude-from="./exclude-one.txt" -e "ssh -oStrictHostKeyChecking=no -i /path/to/key.ppk" --progress /local-one/ user@server.com:/remote-one
失败的rsync命令
rsync -avz --delete --exclude-from="./exclude-two.txt" -e "ssh -oStrictHostKeyChecking=no -i /path/to/key.ppk" --progress /local-two/ user@server.com:/remote-two
错误信息
rsync: [client] failed to open exclude file "./exclude-two.txt": No such file or directory (2) rsync error: error in file IO (code 11) at exclude.c(1482) [client=3.2.7]
异常现象
完整脚本流程中,第二次rsync命令的前后执行cat ./exclude-two.txt都能正常显示文件内容,但rsync就是报错找不到该文件:
rsync -avz --delete --exclude-from="./exclude-one.txt" -e "ssh -oStrictHostKeyChecking=no -i /path/to/key.ppk" --progress /local-one/ user@server.com:/remote-one cat ./exclude-two.txt rsync -avz --delete --exclude-from="./exclude-two.txt" -e "ssh -oStrictHostKeyChecking=no -i /path/to/key.ppk" --progress /local-two/ user@server.com:/remote-two cat ./exclude-two.txt
已尝试的排查操作
- 更换exclude-two.txt文件
- 修改exclude-two.txt的存放路径
- 通过
cat命令生成新的exclude文件供rsync使用 - 手动执行
docker run -ts myimage:tag进入镜像,逐条执行脚本命令,无任何错误
仅在GitLab CI运行镜像时出现该问题,且GitLab日志显示第一次rsync已正常完成。
有没有人遇到过类似问题?
内容的提问来源于stack exchange,提问作者Bob Ramsey
相关产品推荐
相关产品推荐

