You have to execute the command from the root folder of your git repository/project:
$ ls -a
./
../
.git/
.gitignore
.gitlab-ci.yml
Makefile
$ gitlab-runner exec docker <job_name>
You are using docker commands which you shouldn't as gitlab-runner already uses those under the hood.
See $ gitlab-runner exec docker --help for more info on the command.
You have to execute the command from the root folder of your git repository/project:
$ ls -a
./
../
.git/
.gitignore
.gitlab-ci.yml
Makefile
$ gitlab-runner exec docker <job_name>
You are using docker commands which you shouldn't as gitlab-runner already uses those under the hood.
See $ gitlab-runner exec docker --help for more info on the command.
I also came across a similar issue when using VS Code with remote containers and Docker Desktop (WSL2).
I debugged the problem by adding in a --pre-get-sources-script=ls -l "repo_directory", i.e. in the OP's case:
# docker run --name=runner --privileged -t --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /tmp/.gitlab-runner/:/etc/gitlab-runner \
-v
{PWD} \
--workdir $PWD \
--pre-get-sources-script=ls -l /home/fox/Work/docker/core-application/../.git/modules/core-application \
gitlab/gitlab-runner exec docker \
--builds-dir /tmp/builds/ Rspec
In my case, the directory listing (ls -l ...) came up empty! I'm assuming that it mounts the directory as a volume within the container as the same name (/fubar:/fubar), which in my case isn't going to work as it is Docker Desktop with vscode remote containers.
My fix was was to add my named volume as a parameter to a secondary directory, and then setting the --clone-url to point to that directory.
Something like:
# pwd
/workspace/fubar
# gitlab-runner --debug exec docker \
--docker-volumes vscode-workspace:/workspace2 \
--clone-url=file:///workspace2/fubar \
validate;
[output truncated]
...
Starting container 3d49d8e8b977177f34beeae3ae5f09eba288332e109ad79f133e0f160377908b ... job=1 project=0
Fetching changes...
Initialized empty Git repository in /builds/project-0/.git/
Created fresh repository.
Checking out d1a39a4d as detached HEAD (ref is feature/FU-123)...
Skipping Git submodules setup
Executing build stage build_stage=restore_cache job=1 project=0
Skipping stage (nothing to do) build_stage=restore_cache job=1 project=0
Executing build stage build_stage=download_artifacts job=1 project=0
Skipping stage (nothing to do) build_stage=download_artifacts job=1 project=0
Executing build stage build_stage=step_script job=1 project=0
Executing "step_script" stage of the job script
...
I had originally tried changing the --pre-get-sources-script to be cp -R /workspace2/fubar /workspace/ but that complained that the target directory was read-only. Using the --clone-url=file:///workspace2/fubar worked, so I've left it that way.
How to use gitlab-runner exec docker correclty - GitLab CI/CD - GitLab Forum
How to use the docker gitlab-runner to exec stages locally - Stack Overflow
Trouble using gitlab-runner exec docker - How to Use GitLab - GitLab Forum
How does gitlab-runner create a docker container exactly?
gitlab-runner exec works as its own standalone command and runs the job in the context of where the executable is called -- it will not cause the job to be run on a registered runner. It is solely a local operation, so you must have the binary available.
You can run gitlab-runner exec inside of your runner container or a new container if you want.
For example (assuming Linux platform):
docker run --rm \
-v $(pwd):/workspace \ # mount directory to the container
--workdir /workspace \ # set working directory
-v /var/run/docker.sock:/var/run/docker.sock \ # enable docker
--privileged \
--entrypoint="gitlab-runner" \ # set entrypoint
gitlab/gitlab-runner:latest exec docker MY_JOB
Or use doker exec to run the command on your existing container:
docker exec -it my-running-container-name gitlab-runner exec docker linting
Though, you will want to make sure the .gitlab-ci.yml file and project files are present in the container when you start it...
since gitlab 17, the feature is removed https://docs.gitlab.com/runner/commands/#gitlab-runner-exec-removed