Gitlab GitlabRunner如何更改执行用户

Gitlab - GitlabRunner如何更改执行用户

转载自:http://www.fidding.me/article/111

gitlab-cirunner默认使用gitlab-runner用户执行操作;

通过指令ps aux|grep gitlab-runner可以看到:

1
/usr/bin/gitlab-ci-multi-runner run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user gitlab-runner

其中:

--working-directory:设置工作目录, 默认是**/home/{执行user}**

--config:设置配置文件目录,默认是**/etc/gitlab-runner/config.toml**

--user:设置执行用户名,默认是gitlab-runner

因此想要更改userroot只需要重新设置--user属性即可,步骤如下:

  1. 删除gitlab-runner

    1
    sudo gitlab-runner uninstall
  2. 安装并设置--user(例如我想设置为root)

    1
    gitlab-runner install --working-directory /home/gitlab-runner --user root
  3. 重启gitlab-runner

    1
    sudo service gitlab-runner restart

验证一下:

再次执行ps aux|grep gitlab-runner会发现--user的用户名已经更换成root

1
/usr/bin/gitlab-ci-multi-runner run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user root

至此gitlab-runner执行.gitlab-cli.yaml时候便是以root用户去执行操作,再也没有繁琐的权限问题了

来自root的温馨提示:能力越大责任越大!

happy coding!