jenkins slave on docker does not see "sh" command

39 views
Skip to first unread message

Piotr Bracha

unread,
Apr 11, 2019, 11:18:55 AM4/11/19
to jenkins...@googlegroups.com
Hello,
I have a problem with not recognized "sh" command. I have easy pipeline script:
pipeline {
    agent { label "slave-1" }
    options {
        disableConcurrentBuilds()
    }
    stages {
        stage('Setup build variables') {
            steps {
                script {
                    sh 'echo "Setup build variables"'
                }
            }
        }
        stage('Prepare Env') {
            steps {
                script {
                    echo "Prepare Env"
                }
            }
        }
        stage('Invoke Rake') {
            steps{
                script {
                    echo "Invoke Rake"
                }
            }
        }
    }
}

When I run it on jenkins slave (docker image) I have an error:
sh: 1: /var/lib/jenkins/bin/login-bash: not found

On master Jenkins (installed on physical machine not on docker) it works properly.

Aaron Digulla

unread,
Apr 11, 2019, 11:34:50 AM4/11/19
to Jenkins Users
On Thursday, April 11, 2019 at 5:18:55 PM UTC+2, Polak wrote:

When I run it on jenkins slave (docker image) I have an error:
sh: 1: /var/lib/jenkins/bin/login-bash: not found

On master Jenkins (installed on physical machine not on docker) it works properly.

Ceck the "login shell" for the user that runs the Jenkins slave. It should be /bin/bash but seems to be just "login-bash" (without an absolute path) in your case.

Regards,

--
Aaron Digulla

Piotr Bracha

unread,
Apr 15, 2019, 1:28:27 AM4/15/19
to jenkins...@googlegroups.com
Thank you for answer. In this case on physical machine the path "/var/lib/jenkins/bin/login-bash" is proper but it does not exists on docker. I am affraid that dockerized jenkins slave tries use path from physical machine instead of container. Or maybe I should export path to make it visible for container. Docker container was running from root account on physical machine but from some reason:

root@jenkins:~# docker inspect $(docker ps -aq) --format '{{.Config.User}} {{.Name}}' root /jenkins-slave2 jenkins /jenkins-slave1 root /focused_archimedes root /heuristic_fermat root /tender_perlman

"jenkins-slave1" is used as slave mentioned earlier:
root@jenkins:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1090b7609962 jenkinsci/jnlp-slave "jenkins-slave -url …" 12 days ago Up 3 days jenkins-slave1





--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/0681f438-33d8-40b9-bba2-fa612a1d8bd2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Pozdrawiam / Kind regards, 
Piotr Bracha
Administrator Systemów
Vasco Electronics sp. z o.o. S.K.A.
al. Pokoju 1, CTA/350 
31-548 Kraków
NIP 677 236 91 51
 
Vasco Electronics Spółka z ograniczoną odpowiedzialnością Spółka Komandytowo-Akcyjna, Al. Pokoju 1, CTA/350, 31-548 Kraków, Polska, NIP: 6772369151, REGON: 122581850, zarejestrowana w Sądzie Rejonowym dla Krakowa Śródmieścia XI Wydział KRS pod nr KRS: 0000421705, Kapitał zakładowy 50 000 zł (słownie: pięćdziesiąt tysięcy złotych) w całości wpłacony. Klauzula Bezpieczeństwa: treść tej wiadomości wraz z załącznikami stanowią informacje chronione przed ujawnieniem. Jeśli wiadomość ta nie jest przeznaczona dla Ciebie uprzedzamy, że ujawnianie, kopiowanie, rozpowszechnianie lub korzystanie z niej lub z załączników jest zabronione. Jeśli otrzymałeś tę wiadomość przez pomyłkę, uprzejmie prosimy o niezwłoczne zawiadomienie nadawcy i odesłanie jej z powrotem wraz z załącznikami a także usunięcie ze swoich systemów.

Dirk Heinrichs

unread,
Apr 15, 2019, 1:56:31 AM4/15/19
to jenkins...@googlegroups.com
Am Montag, den 15.04.2019, 07:28 +0200 schrieb Piotr Bracha:

Thank you for answer. In this case on physical machine the path "/var/lib/jenkins/bin/login-bash" is proper but it does not exists on docker.

So what exactly IS /var/lib/jenkins/bin/login-bash? A self-written script? I don't have such a thing on my Jenkins systems and I guess no-one else has. In this case you'd need to either make sure your Docker containers have it, too (add it to your Dockerfile), or try to get rid of it.

HTH...

Dirk
-- 
Dirk Heinrichs
Senior Systems Engineer, Delivery Pipeline
OpenText ™ Discovery | Recommind
Recommind GmbH, Von-Liebig-Straße 1, 53359 Rheinbach
Vertretungsberechtigte Geschäftsführer Gordon Davies, Madhu Ranganathan, Christian Waida, Registergericht Amtsgericht Bonn, Registernummer HRB 10646
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden
Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail sind nicht gestattet.

Piotr Bracha

unread,
Apr 15, 2019, 2:21:09 AM4/15/19
to jenkins...@googlegroups.com
Honestly I didn't know it shouldn't be there. I am quite new in jenkins and docker. I didn't write login-bash file. It contains:
#!/bin/sh
#exec /bin/bash -l "$@"
exec /bin/bash "$@"

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Dirk Heinrichs

unread,
Apr 15, 2019, 2:31:18 AM4/15/19
to jenkins...@googlegroups.com
Am Montag, den 15.04.2019, 08:20 +0200 schrieb Piotr Bracha:

Honestly I didn't know it shouldn't be there. I am quite new in jenkins and docker. I didn't write login-bash file. It contains:
#!/bin/sh
#exec /bin/bash -l "$@"
exec /bin/bash "$@"

Yeah, looks like some custom hack to me. What this does is to simply replace the current shell process (hence the "exec") with /bin/bash. Looks pretty redundant to me. So I'd say you could as well get rid of it.

Bye...

Piotr Bracha

unread,
Apr 15, 2019, 2:47:57 AM4/15/19
to jenkins...@googlegroups.com
Ok, I try delete it. We will see does the "sh" command will work on master jenkins after deleting/renaming.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Piotr Bracha

unread,
Apr 15, 2019, 2:52:38 AM4/15/19
to jenkins...@googlegroups.com
I have checked:
root@jenkins:~# docker inspect $(docker ps -aq) --format '{{.Config.User}} {{.Name}}'
jenkins /jenkins-slave1
jenkins@jenkins:~$ echo $SHELL
/bin/bash

czw., 11 kwi 2019 o 17:35 Aaron Digulla <adig...@gmail.com> napisał(a):
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Piotr Bracha

unread,
Apr 15, 2019, 3:07:41 AM4/15/19
to jenkins...@googlegroups.com
When I commented out line in file login-bash I have failing job:
[Pipeline] configFileProvider
provisioning config files...
copy managed file [config/master.key] to file:/var/lib/jenkins/workspace/eo-api-test_bugfix_mails-styling@tmp/config6702095344930085554tmp
[Pipeline] {
[Pipeline] sh
[Pipeline] sh
[Pipeline] }
Deleting 1 temporary files
[Pipeline] // configFileProvider
[Pipeline] sh
[Pipeline] sh
Post stage
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Invoke Rake)
[Pipeline] sh
[Pipeline] junit
Recording test results
Test reports were found but none of them are new. Did leafNodes run? 
For example, /var/lib/jenkins/workspace/eo-api-test_bugfix_mails-styling/spec/reports/SPEC-Account-Associations.xml is 3 days 21 hr old
Without commenting it out job works:


[Pipeline] configFileProvider
provisioning config files...
copy managed file [config/master.key] to file:/var/lib/jenkins/workspace/eo-api-test_bugfix_mails-styling@tmp/config2749435189004461766tmp
[Pipeline] {
[Pipeline] sh
+ mkdir -p /var/lib/jenkins/workspace/eo-api-test_bugfix_mails-styling/config
[Pipeline] sh
+ cp /var/lib/jenkins/workspace/eo-api-test_bugfix_mails-styling@tmp/config2749435189004461766tmp /var/lib/jenkins/workspace/eo-api-test_bugfix_mails-styling/config/master.key
[Pipeline] }
Deleting 1 temporary files
[Pipeline] // configFileProvider
[Pipeline] sh
Do you know how fix this problem - use shell without this "hack script"; maybe some jenkinsfile modification or jenkins settings? Users root and jenkins use /bin/bash as default shell.



Piotr Bracha

unread,
Apr 15, 2019, 4:05:35 AM4/15/19
to jenkins...@googlegroups.com
I have found and fix it but now I have :
/home/jenkins/agent/workspace/eo-api-test_bugfix_mails-styling@tmp/durable-304eb649/script.sh: line 1: bundle: command not found

This is path on dockerized jenkins slave. Project - rails application but bundle command not found.

Dirk Heinrichs

unread,
Apr 15, 2019, 6:04:19 AM4/15/19
to jenkins...@googlegroups.com
Am Montag, den 15.04.2019, 10:05 +0200 schrieb Piotr Bracha:

bundle: command not found

Your container lacks stuff needed by your job, Ruby and/or required Ruby gems in this case. You'd need to rebuild your container image to include all the stuff needed to execute your job.

HTH...

Piotr Bracha

unread,
Apr 15, 2019, 6:47:38 AM4/15/19
to jenkins...@googlegroups.com
I should try some way but it is not mine:  https://github.com/jenkinsci/docker-jnlp-slave

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Dirk Heinrichs

unread,
Apr 15, 2019, 7:06:45 AM4/15/19
to jenkins...@googlegroups.com
Am Montag, den 15.04.2019, 12:47 +0200 schrieb Piotr Bracha:

I should try some way but it is not mine:  https://github.com/jenkinsci/docker-jnlp-slave

So what? No-one keeps you from customizing it. Just write your own Dockerfile that starts with

FROM docker-jnlp-slave

add to it whatever you need and use the resulting image to run your job in.

Piotr Bracha

unread,
Apr 15, 2019, 8:12:18 AM4/15/19
to jenkins...@googlegroups.com
That's perfect. Thank you.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Dirk Heinrichs

unread,
Apr 15, 2019, 8:40:50 AM4/15/19
to jenkins...@googlegroups.com
Am Montag, den 15.04.2019, 14:12 +0200 schrieb Piotr Bracha:

That's perfect. Thank you.

You're welcome. Another possible solution would be to let Jenkins manage the needed stuff. For example we use Groovy a lot, so we installed the Jenkins Groovy plugin. This lets you add Groovy installations to the global Jenkins configuration and whenever a job executes a Groovy build step, Jenkins first checks whether it's installed on the executing slave and installs it if needed.

However, I don't know whether there is an equivalent plugin available for Ruby.

Bye...

Piotr Bracha

unread,
Apr 15, 2019, 8:53:54 AM4/15/19
to jenkins...@googlegroups.com
One more thing:
[Pipeline] sh
+ /home/jenkins/.rvm/rubies/ruby-2.5.1/bin/gem install bundler
/usr/bin/env: ‘ruby’: No such file or directory

It's related with this stage but with exactly which command - could you point me to good track:

stage('Prepare Env') {
            steps {    
                configFileProvider([configFile(fileId: 'master-key', variable: 'MASTER_KEY')]) {
                    sh "mkdir -p ${WORKSPACE}/config"
                    sh "cp ${MASTER_KEY} ${WORKSPACE}/config/master.key"
                }
                sh "echo Test"
                sh "/home/jenkins/.rvm/rubies/ruby-2.5.1/bin/gem install bundler"
                sh "/home/jenkins/.rvm/rubies/ruby-2.5.1/bin/bundle install"
                sh "/home/jenkins/.rvm/rubies/ruby-2.5.1/bin/bundle exec rake db:migrate RAILS_ENV=test"
                
            }
            post {
                success {
                    handleStatus(STAGE_NAME, true);
                }
                failure {
                    handleStatus(STAGE_NAME, false);   
                }
            }
        }

Dirk Heinrichs

unread,
Apr 15, 2019, 9:32:35 AM4/15/19
to jenkins...@googlegroups.com
Am Montag, den 15.04.2019, 14:53 +0200 schrieb Piotr Bracha:

+ /home/jenkins/.rvm/rubies/ruby-2.5.1/bin/gem install bundler
/usr/bin/env: ‘ruby’: No such file or directory

It's related with this stage but with exactly which command - could you point me to good track:

Well, it already tells you (the line starting with "+" is the executed command). "gem" itself is a Ruby script, so it needs Ruby to run. It's either not installed or not in $PATH.

Bye...

Piotr Bracha

unread,
Apr 16, 2019, 1:42:44 AM4/16/19
to jenkins...@googlegroups.com
I have resolved this by adding in slave configuration:
1. Marked "Environment variables".
2. Added environment variable PATH+EXTRA with value /home/jenkins/.rvm/gems/ruby-2.5.1/bin:/home/jenkins/.rvm/gems/ruby-2.5.1@global/bin:/home/jenkins/.rvm/rubies/ruby-2.5.1/bin:/home/jenkins/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Now I need to make work postgresql with pipeline script. Currently on slave I have working postgres:
jenkins@1090b7609962:~$ service postgresql status
9.6/main (port 5432): online

but during building I catch:
Installing pg 1.1.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/home/jenkins/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/pg-1.1.3/ext
/home/jenkins/.rvm/rubies/ruby-2.5.1/bin/ruby -r
./siteconf20190415-13476-1lh45x5.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
You need to install postgresql-server-dev-X.Y for building a server-side
extension or libpq-dev for building a client-side application.
You need to install postgresql-server-dev-X.Y for building a server-side
extension or libpq-dev for building a client-side application.
An error occurred while installing pg (1.1.3), and Bundler cannot continue.
Make sure that `gem install pg -v '1.1.3' --source 'https://rubygems.org/'`
succeeds before bundling.

PS
I have resolved it just by apt-get install libpg-dev.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages