How to change the user of gitlab-runner to root when executing gitlab-ci scripts ?
The default user of gitlab-runner is gitlab-runner
, so the gitlab-ci scripts will run as gitlab-runner
. But how can I switch the user to root, during the execution of the script ?
The automatic switching user script (named su.sh
) is as follows:
#/bin/bash
expect -c "
set timeout 30
spawn su -
expect \":\"
send \"root_password\r\"
interact
It can be executed manually. But through .gitlab-ci.yml
, the switch is not successful.
The .gitlab-ci.yml
is as follows:
stages:
- userchange
userchange:
stage: userchange
script:
- whoami
- sh /home/gitlab-runner/su.sh
So, how to deal with it?