30

How to change the gitlab multi runner build path.

in my server it have /home/gitlab-runner/builds.

I want to change this path to my secondary HDD that is mounted in the same server.

Prem Anand
  • 451
  • 1
  • 4
  • 10

3 Answers3

31

You can change your runners build path by adjusting the config.toml. In the [[runners]] section add or change the builds_dir directory.

For further reference on runner configuration you can check out the documentation here.

Gabriel Devillers
  • 3,155
  • 2
  • 30
  • 53
Fairy
  • 3,592
  • 2
  • 27
  • 36
  • As per your instruction I have changed the path but I got this error message while build mkdir: cannot create directory ‘/git/gitlab/git-runner/993865ac’: Permission denied. – Prem Anand Feb 06 '17 at 10:15
  • @PremAnand The user running the gitlab-runner doesn't have proper permissions. You need to fix that. – Fairy Feb 06 '17 at 11:09
  • Hi can you please tell me what permission I need to give to the gitlab runner and how to find which user is running gitlab runner. – Prem Anand Feb 06 '17 at 12:03
  • 1
    Thank you so much. I fixed the issue by changing the owner and group permission for that folder to gitlab-runner:gitlab-runner and it is working perfectly. You really helped me a lot thank you so much fairy. You are genius – Prem Anand Feb 06 '17 at 12:06
  • Thanks! By the way, this also requires `gitlab-runner restart` for the changes to take effect. – RAM237 Sep 17 '19 at 13:01
  • Does not work for me, after this change and running `gitlab-runner restart`, the systemd unit file still has the old `/home/gitlab-runner` directory specified in the `/etc/systemd/system/gitlab-runner.service` systemd unit file. – Chris Stryczynski Jun 06 '23 at 12:17
11

On macOS I was able to find one more way (can be helpful if you have many runners, I guess):

  1. Edit ~/Library/LaunchAgents/gitlab-runner.plist
    and modify the path under --working-directory to whatever you want

    e.g. from Terminal vim /Users/Me/Library/LaunchAgents/gitlab-runner.plist
    or using your favorite Text Editor

  2. Restart it for the changes to take effect

    gitlab-runner restart

RAM237
  • 903
  • 11
  • 17
  • 4
    This file is created by `gitlab-runner install` with the current working directory. Therefore you can also run `gitlab-runner uninstall`, `cd ` and `gitlab-runner install` to achieve the same effect. – Felix Jul 09 '20 at 14:51
4

One may prefer to setup build directories globally.

In the file /etc/systemd/system/gitlab-ci-multi-runner.service there is a line

Environment="DAEMON_ARGS=run --working-directory /var/lib/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user gitlab-runner"

So, you may change --working-directory /var/lib/gitlab-runner to whatever path you want, and wouldn't specify the --builds-dir on every new registered runner

Environment="DAEMON_ARGS=run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user gitlab-runner"
Piroxiljin
  • 621
  • 6
  • 14
  • 1
    After modify the file, according to the [doc](https://docs.gitlab.com/runner/configuration/init.html#customizing-systemd), you also need to execute `systemctl daemon-reload && systemctl restart gitlab-runner.service`. – Brainor May 29 '23 at 07:12