2

How can I run bower command without sudo using gitlab public runner?

This is my script

image: node:7
before_script:
  - npm install -g bower
  - bower install
...

This is the result I got from the test.

...
npm info ok 
$ bower install
bower ESUDO         Cannot be run with sudo

Additional error details:
Since bower is a user command, there is no need to execute it with superuser permissions.
If you're having permission errors when using bower without sudo, please spend a few minutes learning more about how your system should work and make any necessary repairs.

http://www.joyent.com/blog/installing-node-and-npm
https://gist.github.com/isaacs/579814

You can however run a command with sudo using --allow-root option
ERROR: Build failed: exit code 1

Thank you.

1 Answers1

5

You should add --allow-root after your bower command.
See : https://bower.io/docs/api/#allow-root

CCH
  • 1,516
  • 1
  • 13
  • 24
  • Thanks for answer. It solve the problem, but can I run bower in gitlab CI runner without root? – Christoforus Surjoputro Feb 16 '17 at 13:30
  • 1
    Yes of course it's possible. I don't have enough info to say why it tries to use sudo here, but I see your `npm install` uses the `-g` flag, which may be why it tries tu launch as sudo. Why do you need to install bower globally ? Removing the `-g` should work and not require root. – CCH Feb 16 '17 at 13:36
  • It is possible, but in local machine, I use npm install -g and I can run bower without problem. – Christoforus Surjoputro Feb 16 '17 at 15:12
  • Did you try it ? I don't know what gitlab CI does internally, and i don't see why you would need to install bower globally for CI. – CCH Feb 16 '17 at 15:27
  • I didn't try it, I prefer your --allow-root answer and it works like a charm. Thanks anyway. – Christoforus Surjoputro Feb 16 '17 at 18:54