8

Hi I am new in github actions and I am trying to create a CICD pipline using Github action. I am using a digital ocean droplet UBUNTU 20.04 as my server and I am trying to create a runner as said in ->settings->actions

When I wrote the following command ./config.sh --url https://github.com/basobaasnepal/BasobaasWeb --token DFGFSDF234sf3fg45hd

I got this: Must not run with sudo

I tried to change the from root user to non root user but didn't work. I also tried export {AGENT_ALLOW_RUNASROOT="1"} but no luck there too.

Riwaj Chalise
  • 195
  • 1
  • 2
  • 6

1 Answers1

11

The env variable to use is RUNNER_ALLOW_RUNASROOT="1" You can :

  • Export it before running config.sh using export RUNNER_ALLOW_RUNASROOT="1"
  • Start config.sh like this : RUNNER_ALLOW_RUNASROOT="1" ./config.sh --url...

At the beginning of config.sh you can see the following test :

user_id=`id -u`
if [ $user_id -eq 0 -a -z "$RUNNER_ALLOW_RUNASROOT" ]; then
    echo "Must not run with sudo"
    exit 1
fi

user_id=`id -u` : Gets the uid of the current user and store it to user_id.
$user_id -eq 0 : Compare it with 0 (0 is the uid of root).
-a -z "$RUNNER_ALLOW_RUNASROOT" : -a -z Tests if the variable exists and is not empty.

So in our case we could do RUNNER_ALLOW_RUNASROOT="0" or even RUNNER_ALLOW_RUNASROOT="cool" and it would work but RUNNER_ALLOW_RUNASROOT="" would not work.

I'm curious what was your issue when you tryed to run it as a non-root user ?

Paul
  • 141
  • 1
  • 6
  • The issue when I tried to use non root user seems to be ownership of the file when I did chmod ubuntu ./config.sh then it worked. Your solution too worked can you give more insight why it worked? Thanks anyway. :) – Riwaj Chalise Feb 08 '21 at 07:32
  • I edited my post with an explaination, I hope it's clear :) – Paul Feb 08 '21 at 11:03
  • Awesome description, so removing the condition would work fine too. Do you recommend doing that? – Riwaj Chalise Feb 09 '21 at 02:48
  • 2
    In general it's not a good practise to edit script provided by third parties. For example if you need to upgrade the runner you will download again the script and will have to modify it again. It's easier to play with the environment variable. – Paul Feb 09 '21 at 08:52