Docker GitLab 运行程序中的执行程序未找到可执行文件
Docker executor in GitLab runner doesn't found executable
我有 GitLab CI/CD 集成,并使用 follow yaml 作为项目 CI 配置:
stages:
- test
test_job:
stage: test
tags:
- runner
script:
- pwd
- ls -la
- ls -la ./project
- ls -la ./project/build.sh
- ./project/build.sh
这是执行器的config.toml部分:
[[runners]]
name = "GitLab Runner"
url = "https://srvgitlab.maxi-net.ru/"
token = "UJLBiJ86coJT5iPKghNx"
tls-ca-file = "/etc/gitlab-runner/certs/srvgitlab.maxi-net.ru.crt"
executor = "docker"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
[runners.docker]
tls_verify = false
image = "runner:latest"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache"]
pull_policy = ["if-not-present"]
shm_size = 0
这是Dockerfile
的内容:
FROM alpine:latest
LABEL maintainer='psheom@maxi-net.ru'
比起我构建一个图像:
docker build -t runner .
这是build.sh
的内容:
#!/bin/bash
sleep 10
这是作业的输出:
$ pwd
/builds/devs/tg/reps/gitlab-runner
$ ls -la
total 36
drwxrwxrwx 4 root root 4096 May 17 15:40 .
drwxrwxrwx 4 root root 4096 May 17 15:25 ..
drwxrwxrwx 6 root root 4096 May 17 15:40 .git
-rw-rw-rw- 1 root root 175 May 17 15:40 .gitlab-ci.yml
drwxrwxrwx 3 root root 4096 May 17 15:30 project
$ ls -la ./project
total 28
drwxrwxrwx 3 root root 4096 May 17 15:30 .
drwxrwxrwx 4 root root 4096 May 17 15:40 ..
-rw-rw-rw- 1 root root 141 May 17 15:25 Dockerfile
-rwxrwxrwx 1 root root 20 May 17 15:30 build.sh
$ ls -la ./project/build.sh
-rwxrwxrwx 1 root root 20 May 17 15:30 ./project/build.sh
$ ./project/build.sh
/bin/sh: eval: line 113: ./project/build.sh: not found
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 127
为什么 /bin/sh
没有看到文件?
/bin/sh: eval: line 113: ./project/build.sh: not found
是的,文件 ./project/build.sh
确实存在,但是当它是 shell 脚本时,第一行将作为 运行:
的可执行文件处理
#!/bin/bash
由于 bash
不附带 alpine,您会得到一个找不到的文件(不幸的是,来自 Linux 的错误消息在这里不是很有用)。如果 shell 脚本中有 windows 换行符,也会发生这种情况,因为它会查找 /bin/bash\r
(其中 \r
是回车 return 字符)。
要修复,使用您的简单脚本,您可以只使用 /bin/sh
,bash
没有关于 sleep
命令的特定内容:
#!/bin/sh
我有 GitLab CI/CD 集成,并使用 follow yaml 作为项目 CI 配置:
stages:
- test
test_job:
stage: test
tags:
- runner
script:
- pwd
- ls -la
- ls -la ./project
- ls -la ./project/build.sh
- ./project/build.sh
这是执行器的config.toml部分:
[[runners]]
name = "GitLab Runner"
url = "https://srvgitlab.maxi-net.ru/"
token = "UJLBiJ86coJT5iPKghNx"
tls-ca-file = "/etc/gitlab-runner/certs/srvgitlab.maxi-net.ru.crt"
executor = "docker"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
[runners.docker]
tls_verify = false
image = "runner:latest"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache"]
pull_policy = ["if-not-present"]
shm_size = 0
这是Dockerfile
的内容:
FROM alpine:latest
LABEL maintainer='psheom@maxi-net.ru'
比起我构建一个图像:
docker build -t runner .
这是build.sh
的内容:
#!/bin/bash
sleep 10
这是作业的输出:
$ pwd
/builds/devs/tg/reps/gitlab-runner
$ ls -la
total 36
drwxrwxrwx 4 root root 4096 May 17 15:40 .
drwxrwxrwx 4 root root 4096 May 17 15:25 ..
drwxrwxrwx 6 root root 4096 May 17 15:40 .git
-rw-rw-rw- 1 root root 175 May 17 15:40 .gitlab-ci.yml
drwxrwxrwx 3 root root 4096 May 17 15:30 project
$ ls -la ./project
total 28
drwxrwxrwx 3 root root 4096 May 17 15:30 .
drwxrwxrwx 4 root root 4096 May 17 15:40 ..
-rw-rw-rw- 1 root root 141 May 17 15:25 Dockerfile
-rwxrwxrwx 1 root root 20 May 17 15:30 build.sh
$ ls -la ./project/build.sh
-rwxrwxrwx 1 root root 20 May 17 15:30 ./project/build.sh
$ ./project/build.sh
/bin/sh: eval: line 113: ./project/build.sh: not found
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 127
为什么 /bin/sh
没有看到文件?
/bin/sh: eval: line 113: ./project/build.sh: not found
是的,文件 ./project/build.sh
确实存在,但是当它是 shell 脚本时,第一行将作为 运行:
#!/bin/bash
由于 bash
不附带 alpine,您会得到一个找不到的文件(不幸的是,来自 Linux 的错误消息在这里不是很有用)。如果 shell 脚本中有 windows 换行符,也会发生这种情况,因为它会查找 /bin/bash\r
(其中 \r
是回车 return 字符)。
要修复,使用您的简单脚本,您可以只使用 /bin/sh
,bash
没有关于 sleep
命令的特定内容:
#!/bin/sh