In Gitlab Ci The Gitlab Runner Choose Wrong Executor

In gitlab CI the gitlab runner choose wrong executor

@edit: From here:

tags is used to select specific Runners from the list of all Runners that are allowed to run this project.

As resolved in the comments, your shell executed must have been tagged with the docker tag, which resulted in him being picked as the executor for the job.

This is my old answer:

You are using a shell executor, and from here:

Shell executor is a simple executor that allows you to execute builds locally to the machine that the Runner is installed

...

If GitLab Runner is installed on Linux from the official .deb or .rpm packages, the installer will try to use the gitlab_ci_multi_runner user if found. If it is not found, it will create a gitlab-runner user and use this instead.
....

In some testing scenarios, your builds may need to access some privileged resources

...

Generally it's unsafe to run tests with shell executors. The jobs are run with the user's permissions (gitlab-runner) and can "steal" code from other projects that are run on this server. Use it only for running builds on a server you trust and own.

The commands your are running are executed as gitlab-runner user and don't have permissions to run apt-get command. You can:

  • move to docker
  • grant user gitlab-runner the permissions he needs to run specified commands. gitlab-runner may run apt-get without sudo, also he will need perms for npm install and npm run.
  • grant sudo nopasswd to user gitlab-runner. Add gitlab-runner ALL=(ALL) NOPASSWD: ALL (or similar) to /etc/sudoers on the machine gitlab-runner is installed and change the lines apt-get update to sudo apt-get update, which will execute them as privileged user (root).

Shell executor does not work on registered gitlab-runner

Actually here is the solution.

Settings were changed somehow in gitlab profile, shared runners became enabled and that caused an impact on my runner and executor.

Running local GitLab CI with shell executor and flag --user $USER for 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)

Gitlab CI Different executor per stage

Not exactly stages but you can have different jobs to be run by different runners using tags configuration option which should give you exactly what you want.

Add (either during runner creation or later in Project settings -> Runners) tag docker to the Docker runner and tag shell to the shell runner. Then you can set the tags in your .gitlab-ci.yml file:

stages:
- test
- deploy

tests:
stage: test
tags:
- docker
script:
- [test routine]

deployment:
stage: deploy
tags:
- shell
script:
- [deployment routine]

Gitlab Runner with Docker and shell error — Permission denied

IMHO, using shell executor on a Docker runner with already mounted Docker socket on it is not a good idea. You'd better use docker executor, which will take care of everything and probably is how it's supposed to be run.

Edit

Alternatively, you can use a customized Docker image to allow using the shell executor with root permissions. First, you'll need to create a Dockerfile:

FROM gitlab/gitlab-runner:latest
# Change user to root
USER root

Then, you'll have to build the image (here, I tagged it as custom-gitlab-runner):

$ docker build -t custom-gitlab-runner .

Finally, you'll need to use this image:

docker run -d \
--name gitlab-runner \
--restart always \
-v /srv/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
custom-gitlab-runner:latest


Related Topics



Leave a reply



Submit