How to use sudo in build script for gitlab ci?

前端 未结 1 651
走了就别回头了
走了就别回头了 2020-12-24 13:50

When I would like to do something that requiers sudo privelegies, the build process stucks and when ps aux for that command, it hanging in the list but doing no

相关标签:
1条回答
  • 2020-12-24 14:41

    There are a couple of ways to resolve this.

    Grant sudo permissions

    You can grant sudo permissions to the gitlab-runner user as this is who is executing the build script.

    $ sudo usermod -a -G sudo gitlab-runner
    

    You now have to remove the password restriction for sudo for the gitlab-runner user.

    Start the sudo editor with

    $ sudo visudo
    

    Now add the following to the bottom of the file

    gitlab-runner ALL=(ALL) NOPASSWD: ALL
    

    Do not do this for gitlab runners that can be executed by untrusted users.

    SSH Runner

    You can configure the gitlab-ci-runner to connect to a remote host using SSH. You configure this to use a user remotely that has sudo permissions, and perform the build using that user. The remote host can be the same machine that the gitlab runner is executing on, or it can be another host.

    This build user account will still need to have sudo and passwordless permissions. Follow the instruction below, except replace gitlab-runner with the build user.

    0 讨论(0)
提交回复
热议问题