I have GitLab CI/CD integration, and use follow yaml as project CI config:
stages:
- test
test_job:
stage: test
tags:
- runner
script:
- pwd
- ls -la
- ls -la ./project
- ls -la ./project/build.sh
- ./project/build.sh
This is config.toml part of the executor:
[[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
This is contents of Dockerfile
:
FROM alpine:latest
LABEL maintainer='psheom@maxi-net.ru'
Than I build an image:
docker build -t runner .
This is contents of build.sh
:
#!/bin/bash
sleep 10
And this is output of a job:
$ 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
Why /bin/sh
doesn't see a file?
/bin/sh: eval: line 113: ./project/build.sh: not found
Yes, the file ./project/build.sh
does exist, but when it's a shell script, the first line gets processed as the executable to run:
#!/bin/bash
Since alpine doesn't ship with bash
, you'll get a file not found (unfortunately the error message from Linux isn't very helpful here). This can also happen if you have windows linefeeds in the shell script, since it would look for /bin/bash\r
(where \r
is the carriage return character).
To fix, with your simple script, you can just use /bin/sh
instead, there's nothing bash
specific about a sleep
command:
#!/bin/sh