I try to set up a CI environment on a local GitLab install.
I am testing basic shell commands that need to be run within the regular user (the value of $USER
) environment.
By default the gitlab-runner service is configured with --user gitlab-runner
.
So first I followed the answer provided at Change Gitlab CI Runner user to assign another user.
This seemed to work as the output of ps aux | grep runner
is as expected and I hit the clear_console
error from .bash_logout
described at https://gitlab.com/gitlab-org/gitlab-runner/-/issues/4559.
After commenting out the content of .bash_logout
I now get the following error.
Running with gitlab-runner 14.3.2 (e0218c92)
...
Getting source from Git repository
00:00
Fetching changes with git depth set to 50...
error: could not lock config file /home/gitlab-runner/builds/y762gpjf/0/root/test.tmp/git-template/config: Permission denied
This happens before any command from .gitlab-ci.yml
gets interpreted so I am stuck here.
Also it seems that gitlab-runner is definitely not designed to be run with the regular user account. Is that a fair assumption?
Indeed, the new user did not have access to the working directory of the runner. So before installing the runner I ran
sudo usermod -aG gitlab-runner $USER
sudo chmod g+wx /home/gitlab-runner/
and then
sudo gitlab-runner install --user=$USER --working-directory=/home/gitlab-runner
As Davide mentioned in the comments, when you update the user for gitlab-runner, you also need to update its working directory to ensure that it has permissions to that directory. Alternatively, you could grant the new user access to /home/gitlab-runner
, it's your choice. To install the gitlab-runner with a different user and working directory, the command is: gitlab-runner install --user=my_user --working-directory=/home/my_user
(reference)