Gitlab-Runner doesn't have sudo access on OSX - macos

I have installed gitlab-runner on a new OSX device. My runner is register and launch correctly.
But when i start a job, I have this error
sudo gem install fastlane
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
sudo: a password is required
What can I do avoid this error and let gitlab-runner have sudo access to execute anything ?

Most probably you granted the sudo permission to your gitlab-runner user, but you did not remove the password restriction for sudo for the gitlab-runner user. Here you can find how to do it.
However I would not recommend using sudo. You could use Bundler and then install fastlane with bundler for this project and not globally.
gem install bundler -> you will get a Gemfile for the current directory (root of the project)
put gem "fastlane" into the Gemfile
install it with bundle install (you can run this command with your gitlab-runner user in jobs)
For running fastlane lanes use: bundle exec fastlane <name_of_the_lane>.

Related

Fastlane doesn't work after updating to macOS Catalina [using Fishshell]

"The file '/usr/local/bin/fastlane' specified the interpreter '/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby', which is not an executable command."
Managed to fix it by:
1.) sudo gem install fastlane -NV
After this, try running your fastlane commands. In my case they didn't work but the output did suggest to run the next commands:
2.) sudo gem install bundler:2.0.2
3.) bundle update --bundler
And now I'm running it using:
bundle exec fastlane your_lane
(instead of fastlane your_lane)

Installing bundler within Jenkins Docker image

Is it possible to install Ruby within a docker image, specifically Jenkins?
I can see from the docs that you can attach to a container or use docker exec -i -t 4e2bf4128e3e bash. This will log me in as jenkins#4e2bf4128e3e.
But if I try and install anything
apt-get install ruby 2.0.0 # Yes will install rvm, this is just an example
I get
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
And when I try
sudo apt-get install ruby 2.0.0
Then I get sudo command not found.
The problem you have is that, as you can see here, the jenkins docker images executes commands as the jenkins user which is forbidden to use apt.
On https://hub.docker.com/_/jenkins/ you have some documentation, namely the "Installing more tools" section which advise you to do this:
FROM jenkins
# if we want to install via apt
USER root
RUN apt-get update && apt-get install -y ruby make more-thing-here
USER jenkins # drop back to the regular jenkins user - good practice
You could create your own image, that layers those two images
Dockerfile
FROM jenkins
FROM ruby
...
Now you have a docker container of your own that has both ruby AND jenkins.

Bundler 1.12.0 cannot be run as a user with no $HOME directory

With the latest version of bundler, I keep getting errors such as:
STDOUT: There was an error while trying to write to /home/user1/.bundle/cache/compact_index/rubygems.org.443.29b0360b937aa4d161703e6160654e47.
It is likely that you need to grant write permissions for that path.
I'm running sudo su - user2 bundle install synapse, where user2 has no HOME directory. I'm trying to install Airbnb Smartstack using Chef.
It seems that the latest version of Bundler insists on writing the new index cache files to $HOME/.bundle. This means that commands such as:
sudo su - homelessuser bundle install synapse
...fail when they try to write to the $HOME/.bundle of the user that called sudo ....
As a workaround, I'm pinning my bundler version to 1.11.2 for now.
Note The GitHub issue for this can be found here

Ruby Gems : sudo gems not showing with gems

I have a sudo rights on my ssh user. I can not run sudo bundle install command but can run bundle install without sudo.
Once I run the bundle install, Few gems get install but those who need gcc and c++ compiler I have to install in sudo permissions like sudo gem install json -v '1.8.0'.
Now if I try to run bundle that gem is not available due to installed with sudo permission.
Is there any other way to install such compiler gems without sudo?
I was not getting the right environement for installing ruby and gemsets . But
rvmsudo worked for me
I tried installing those gems which required compiler like
rvmsudo gem install json -v '1.8.0'
And it worked for me.
I am having only local user access which does not have any rights to run commands like yum

Errno::EACCES: Permission denied when installing gems via gitlab

I'm trying to setup gitlab and thus install some gems from another user account using sudo,
but I'm constantly getting Permission denied error.
sudo -u gitlab -H bundle install --deployment --without development test postgres
> Using ... ( a lot of successful gems there )
> Using pygments.rb (0.3.2) from https://github.com/gitlabhq/pygments.rb.git (at master)
> Errno::EACCES: Permission denied - pygments.rb-0.3.2.gem
> An error occurred while installing pygments.rb (0.3.2), and Bundler cannot continue.
> Make sure that `gem install pygments.rb -v '0.3.2'` succeeds before bundling.\
sudo -u gitlab -H gem install pygments.rb -v '0.3.2'
> Successfully installed pygments.rb-0.3.2
> 1 gem installed
> Installing ri documentation for pygments.rb-0.3.2...
> Installing RDoc documentation for pygments.rb-0.3.2...
# no matter how many times I run this command, I always get the same output
# as if the gem installation doesn't stick
# I've tried to chmod
chmod 777 -R /usr/local/lib/ruby
# then Again
sudo -u gitlab -H bundle install --deployment --without development test postgres
# same result, Errno::EACCES: Permission denied - pygments.rb-0.3.2.gem
Lain suggested to try to install the bundles into another sub directory. When that worked out, it became clear the problem was about permissions in the current directory.
Executing chown -R gitlab:gitlab . has solved the problem.
In the gitlab installation guide there is a gem install command preceding our story that was ran as root and probably the gemfile or some other file had permissions change during that.
This is a permissions bug in ruby-2.0.0-p195 rvm with bundle install
are you using rvm? did you try chmod with sudo?
chmod 755 (or 777) ~/.rvm/gems/ruby-2.0.0-p195/build_info/
I did the following and got things working.
I changed the permission for the Gemfile. i.e. chmod 755 Gemfile
Then I did a sudo bundle install. This got things working and all the gems got installed. I could then start my app by rails server
Make sure your Gemfile.lock is owned by the user running the command
Although Alex's answer is correct,this worked for me as well
sudo chown -R git:git /path/to/external/volume
I'm using Digital Ocean's Gitlab Image

Resources