Yes
Yes

Reputation: 423

Setting up gitlab-runner to run a shell command on a local machine upon push on specified repository

I have a repository on my gitlab server. Whenever I push to a specified branch I would like to fetch the newest version of the branch and run a script.

So far I have registered the runner in my repository under repository-sidebar -> Settings -> CI/CD -> runners

I used the provided instructions and created the provided example .gitlab-ci.yml file in the repository. It only makes use of echo commands that do not require superuser privileges on my machine.

When I push I receive a notification

"Failed pipeline for [Repositoryname]"

I followed the following instructions specified in the gitlab runner installation instructions:

# Download the binary for your system
sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64

# Give it permissions to execute
sudo chmod +x /usr/local/bin/gitlab-runner

# Create a GitLab CI user
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash

# Install and run as service
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner start
Command to register runner
sudo gitlab-runner register --url https://git.[Address-Name].de/ --registration-token $REGISTRATION_TOKEN

Issuing gitlab-runner run results in the following error message upon a push:

Checking for jobs... received job=241221 repo_url=[URL]
WARNING: Preparation failed: getwd: stat .: permission denied job=241221 project=7 runner=[RUNNER TOKEN]

This happens when I run the runner with both sudo gitlab-runner run and just gitlab-runner run.


Upvotes: 1

Views: 3715

Answers (1)

Yes
Yes

Reputation: 423

The problem was running "sudo gitlab-runner" as stated in the gitlab instructions, which caused the config.toml folder to be a root owned directory on the machine instead of the user owned one. registering without sudo and running without sudo worked for this

Upvotes: 1

Related Questions