Trouble configuring Jenkins - ruby

When I go to run a ruby script as a build task, this is the error I get.
I am not sure what is wrong with the setup.
my RUBY_HOME "/home/bitnami/.rvm/rubies/ruby-1.9.3-p374"
Any Ideas?
Started by user User Name
Building in workspace /opt/bitnami/apps/jenkins/jenkins_home/workspace/Test
[Test] $ ruby -v /opt/bitnami/apache-tomcat/temp/hudson7369076924945073821.rb
FATAL: command execution failed
java.io.IOException: Cannot run program "ruby" (in directory "/opt/bitnami/apps/jenkins/jenkins_home/workspace/Test"): error=2, No such file or directory

To use RVM-managed ruby in Jenkins jobs, you have to source rvm in the build steps, like . /path/to/rvm/scripts/rvm. Then you need to set which ruby to use with rvm use. I use it extensively with no errors.

Related

Docker Ruby Bundle Permissions Error on Build

Using docker-compose, I'm trying to build a Ruby application (ruby-app). However near the end of the build it errors out:
There was an error while trying to write to `/ruby-app/Gemfile.lock`. It is likely
that you need to grant write permissions for that path.
ERROR: Service 'ruby-app' failed to build: The command '/bin/sh -c bundle install --jobs 4' returned a non-zero code: 23
Not sure why this permissions error is cropping up now, it has been building fine for some time.
The problem was that I modified the Gemfile and I was expecting bundler inside of the container to generate the new Gemfile.lock based on the changes.
To fix the issue, I ran bundle install outside of the container. This generated a new Gemfile.lock on my local filesystem and then I was able to build the container as expected.

Ruby: 'bundle exec' throws error for all shell commands

In my project, I have a Gem that contains a shell script in its bin folder, let's call the script do_something.sh.
do_something.sh actually executes a ruby script using Jruby command, the script is called ruby_script.rb.
I am trying to call do_something.sh from my project using:
bundle exec do_something.sh
it keeps throwing errors for all shell commands in the script. I erased all the contents of the script and added only one line "echo 'Hello'" and it is still throwing the following error
NoMethodError: undefined method echo' for main:Object
/usr/local/rvm/gems/ruby-2.1.1#projectName/gems/gemName/bin/do_something.sh:10:in'
/usr/local/rvm/gems/ruby-2.1.1#projectName/bin/do_something.sh:23:in load'
/usr/local/rvm/gems/ruby-2.1.1#projectName/bin/do_something.sh:23:in'
Edit#1
All the files has execute permission.
I also tried to put ruby_script.rb in the bin directory where are files are executables (according to a rule in the gemspec file) and tried calling
bundle exec ruby_script.rb
I get the error "bundler: command not found: ruby_script.rb"
bundle exec ruby ruby_script.rb
I get the error "ruby: No such file or directory -- ruby_script.rb (LoadError)"
Why am I getting this error and how can I solve it? I want to be able to either run do_something.sh or ruby_script.rb. Right now, ruby_script.rb is not recognised and do_something.sh does not recognise the commands.
Ok, finally after two days, I was able to make it work.
bundle install installs my GEM and creates a ruby wrapper by default to sh files in the 'bin' directory. So, when I call my script using bundle exec the ruby wrapper gets called first and it calls my script using a ruby 'load' function. This load function expects a ruby file and that is why all my shell script in the file threw errors, because they were expected to be in ruby.
A workaround to this is installing my gem before 'bundle install' using the following command:
gem install --no-wrapper my-gem
Apparently this command disabled creating the ruby wrapper and I was finally able to call the script using bundle execute do_something.sh
Try specifying sh when you run bundle exec. The NoMethodError is from the script being executed in ruby and not sh.
bundle exec sh do_something.sh
In order to make it work. Setting_up_permissions_on_a_script
First: you have to change the mode for the file using chomd +x file_path
Second: Now you can call either by bundle exec file_path or ./file_path
N.B
1: Don't forget to add #!/bin/sh on top of the file.
2: And do check with deploy-a-shell-script-with-ruby-gem-and-install-in-bin-directory will definitely help you.
Hope this help you!
According to Rubygems Specification Reference, executables included in the gem
... must be executable Ruby files. Files that use bash or other interpreters will not work.
In order to to add an executable to a gem please make sure to read the Adding an executable section on Rubygems Guide.
Eventually you'll be able to run the executable like this:
bundle exec do_something
where bundle exec part is optional.

Cannot install gem - make is not recognized as an internal or external command operable program or batch file

I wanted to install the rspec-rails gem with ruby 1.9.3 on windows 7. I got some errors saying that some json libraries could not be installed. So, I used the instructions below to solve it.
Source = The 'json' native gem requires installed build tools
Download [Ruby 1.9.3][2] from [rubyinstaller.org][3]
Download DevKit file from [rubyinstaller.org][3]
For Ruby 1.9.3 use [DevKit-tdm-32-4.5.2-20110712-1620-sfx.exe][4]
Extract DevKit to path C:\Ruby193\DevKit
Run cd C:\Ruby193\DevKit
Run ruby dk.rb init
Run ruby dk.rb review
Run ruby dk.rb install
To return to the problem at hand, you should be able to install JSON (or otherwise test that your DevKit successfully installed) by running the following commands which will perform an install of the JSON gem and then use it:
gem install json --platform=ruby
ruby -rubygems -e "require 'json'; puts JSON.load('[42]').inspect"
When I execute the above first step, I get the error -
C:\Ruby193\DevKit>gem install json --platform=ruby
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
C:/Ruby193/bin/ruby.exe extconf.rb
creating Makefile
make
'make' is not recognized as an internal or external command,
operable program or batch file.
Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1 for inspection.
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1/ext/json/ext/generator/gem_make.out
I am trying to solve the above error now -
'make' is not recognized as an internal or external command, operable program or batch file.
using make is not recognized as an internal or external command - Qt SDK - Windows
If someone already knows how to fix this, then please help me. I have been struggling to install gems and I am failing for so many days. I am wondering if ruby is so difficult.
The DOSKEY approach failed !!!
I did this - Install Mingw and installed all its developer tools and base stuff. Then added C:\MinGW\bin to environment variables to find mingw32-make.exe. Then, I ran the DOSKEY make=mingw32-make followed by the ruby command. I got the same error. I am guessing that the ruby code is spawning off a hidden cmd window and thats why the command is not working. DOSKEY is valid only in the cmd window in which you run it.
Next step - Not so nice, but, I'll change mingw32-make.exe to make.exe and see.
Failed again with a new error -
Temporarily enhancing PATH to include DevKit... Building native
extensions. This could take a while... ERROR: Error installing json:
ERROR: Failed to build gem native extension.
C:/Ruby193/bin/ruby.exe extconf.rb creating Makefile
make generating generator-i386-mingw32.def compiling generator.c In
file included from generator.c:1:0: ../fbuffer/fbuffer.h:5:18: fatal
error: ruby.h: No such file or directory #include "ruby.h"
^ compilation terminated. Makefile:204: recipe for target 'generator.o' failed make: *** [generator.o] Error 1
Gem files will remain installed in
C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1 for inspection. Results
logged to
C:/Ruby193/lib/ruby/gems/1.9.1/gems/json-1.8.1/ext/json/ext/generator/gem_make.out
What do I do now ?
Most of the Ruby gems are developed for Unix and require some extra tools to make it work on Windows.
In order to install those gem in Windows, you need Ruby DEVELOPMENT KIT from the download link (choose the correct installer based on your Ruby version).
Extract the installation to some permanent location. In my system, it is C:\RubyDevKit.
Open command prompt and cd to the extracted location and execute the following commands
cd C:\RubyDevKit
ruby dk.rb init
ruby dk.rb install
devkitvars.bat
The last command is what I missed initially and took sometime to figure out. Now try installing your gem; it worked for me.
Additional Information
The Ruby Development Kit has a component called MinGW which is used to run Unix command on Windows.
The below error, in my case, was Ruby Development Kit not added to the system path variable
make
'make' is not recognized as an internal or external command,
operable program or batch file.
The command devkitvars.bat adds the Development Kit to the system path.
Try installing gnuwin-32 make and then change environment variable PATH to point to C:\Program Files (x86)\GnuWin32\bin
Ruby installation wizard asks you "Add Ruby executables to your PATH", for me, easy solution is to uninstall ruby and install again, this time checking the check box "Add Ruby executables to your PATH"
With the latest version of Ruby 2.4.2, the dev kit is included in the installation so you don't need to follow the separate install instructions. Just uninstall existing ruby and reinstall the new one here https://rubyinstaller.org/downloads/.
Once finished, it'll open up a command prompt on which you need to select option 3 to include the dev kit. However, at the time of writing it's so buggy and you may or may not have issues installing.
I have tried to setup ruby on rails on a windows system, although there are one click installers that install ruby itself and rails, many of the gems rely on a posix based operating system to be compiled, thus making it near impossible to do actual work on windows.
My advise would be to get yourself a linux system, perhaps unbuntu on your system and dual boot, or get a virtual pc software, like this one, or any of the other options, and try installing ruby from there.

ROR Error: project directory contains "gemfile" but shows error "could not locate Gemfile" after executing bundle show

I am executing a command rails new sample_app. After creating a project sample_app, I executed bundle show command but it Could not locate Gemfile.
I Google and found stackoverflow solutions 1 2 3 in which they didn't find gemfile whereas in my case i have. Suggest some solutions.
I think you should be in sample_app directory. For this run on command prompt cd sample_appthen execute bundle installthen bundle show

How to build and run a Ruby command-line tool found on github?

Hi cloned a simple app ( https://github.com/cfx/twix) on github that allows me to send Twitter messages from the console, but I'm not sure how to run it.
I now have a folder in my users/name director called Twix. Inside twix, I have these folders created by the app.
README Rakefile bin lib test
The readme doesn't provide a lot of instruction to get things started. It just tells you what to do after the program's running (see below).
Questions: What command do I use to get this started? What folder do I need to be in?
The README
Twix 0.0.1
Simple twitter client for console
Keys:
q - quit
t - write new message
If you want to post your twit, finish you message with !SEND
If you want abort and back to your feed, finish your message with !EXIT
new features soon
This program is packaged as a gem. The following command will install the gem (run it in the Twix directory):
rake package && gem install pkg/twix-0.0.1.gem
You can now run the program from anywhere with the twix command.
Edit
The first thing I saw in the repository was the Rakefile, meaning there were some rake tasks defined. When you find yourself in this case, running rake -T is your best bet as it will show you the rake tasks available. Its output was the following:
(in /home/benoit/code/clones/twix)
rake clobber_package # Remove package products
rake gem # Build the gem file twix-0.0.1.gem
rake package # Build all the packages
rake repackage # Force a rebuild of the package files
I picked the command that would be the most likely to build the gem: the package one. I guess the gem task would have worked as well.
Running rake package gave me the following output:
(in /home/benoit/code/clones/twix)
mkdir -p pkg
WARNING: no homepage specified
Successfully built RubyGem
Name: twix
Version: 0.0.1
File: twix-0.0.1.gem
mv twix-0.0.1.gem pkg/twix-0.0.1.gem
All that was left was to install the pkg/twix-0.0.1.gem created by the previous command:
gem install pkg/twix-0.0.1.gem
There's another case you could have encountered: the presence of a twix.gemspec in the root directory of the application. In this case, running:
gem build twix.gemspec
would have built the gem, the installation step remains the same.
ruby ./bin/twix
or
ruby -I lib ./bin/twix

Resources