Pergunta

I have a Jenkins job that uses Publish Over SSH Plugin to send script.sh to a remote machine and execute it. The script looks like that:

cd some_path
bundle
bundle exec rakep build

I get the following error

Your Ruby version is 1.9.3, but your Gemfile specified 2.1.0

The same script runs correctly if I SSH to the machine and run it manually or do

echo "bash script.sh" | ssh me@remote_machine

After some research I found that this error on a local machine can be fixed by using a login shell or (re)installing bundle. I did the latter with no effect. The former may be the direction, but the Jenkins plugin does not allow me to configure anything which sounds like it.

I thought that the cause of error might that the plugin SSHs in such a way (non-login shell?) that some environmental variables are not set - so I added export VAR=value for any VAR I found in env while manually SHHed that had anything to do with Ruby. Still no effect.

I am not familiar with Ruby and hope that it is not a silly problem. Any help would be appreciated.

EDIT:

Using which ruby I found out that Jenkins was indeed using another Ruby executable than me, even though we used the same SSH credentials.

Foi útil?

Solução 5

Thanks for your answers, unfortunately they did not work.

I solved it using

~/.rvm/bin/rvm 2.1 do bash script.sh

Outras dicas

Try adding this line on top of your script:

#!/bin/bash --login

If you are using rvm (which I believe you do), rvm is changing current version of ruby every time you enter the folder containing Gemfile. This bit of functionality is stored in ~/.bash_profile which needs to be loaded - this is done by adding --login option.

I have solved a similar problem configuring the slave as follow:

enter image description here

Are you using rvm or rbenv? They're probably not loaded in the non-interactive ssh session.

I had a similar problem, the reason was that the PATH variable was different when logging in from a console or when running a script via SSH.

You can take a look at how PATH differs and add the missing paths to the script that you are running

export PATH=$PATH:/missing/path/here
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top