Skip to content
This repository has been archived by the owner on Jul 4, 2018. It is now read-only.

Unable to run script.sh inside docker agent #193

Open
tomdottom opened this issue Jul 5, 2017 · 5 comments
Open

Unable to run script.sh inside docker agent #193

tomdottom opened this issue Jul 5, 2017 · 5 comments

Comments

@tomdottom
Copy link

When trying to run the following declarative pipeline:

pipeline {
    agent { docker 'alpine' }
    stages {
        stage('Test') {
            steps {
                sh('printenv')
            }
        }
    }
}

I get the error:

[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Agent Setup)
[Pipeline] sh
[TmpTest] Running shell script
+ docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
Digest: sha256:1072e499f3f655a032e88542330cf75b02e7bdf673278f701d7ba61629ee3ebe
Status: Image is up to date for alpine:latest
[Pipeline] }
[Pipeline] // stage
[Pipeline] sh
[TmpTest] Running shell script
+ docker inspect -f . alpine
.
[Pipeline] withDockerContainer
Jenkins does not seem to be running inside a container
$ docker run -t -d -u 107:113 -w /var/lib/jenkins/workspace/TmpTest -v /var/lib/jenkins/workspace/TmpTest:/var/lib/jenkins/workspace/TmpTest:rw,z -v /var/lib/jenkins/workspace/TmpTest@tmp:/var/lib/jenkins/workspace/TmpTest@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** --entrypoint cat alpine
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Provision Server)
[Pipeline] sh
[TmpTest] Running shell script
sh: /var/lib/jenkins/workspace/TmpTest@tmp/durable-1abfbc69/script.sh: not found
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
$ docker stop --time=1 db551b51404ba6305f68f9086320634eeea3d515be134e5e55b51c3c9f1eb568
$ docker rm -f db551b51404ba6305f68f9086320634eeea3d515be134e5e55b51c3c9f1eb568
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE

When monitoring the pipelines @tmp directory whilst its running I can see script.sh created.

some system details

Jenkins running as a single node system which has docker installed.

Jenkins v2.60.1
(all plugins fully updated)
docker --version
Docker version 17.06.0-ce, build 02c1d87
@AndresCidoncha
Copy link

Same here, some fix?
My config:

  • Jenkins 2.60.2
  • Docker version 17.03.1-ce, build c6d412e

@AndresCidoncha
Copy link

@tomdottom The docker image must have inside the jenkins agent ready for run. In my case, a workaround is use a custom Dockerfile with base of https://hub.docker.com/r/jenkinsci/slave/~/dockerfile/ and adding the things I need (docker for example).
Once you have a jenkins agent running inside the container, the sh will exec correctly.

@tomdottom
Copy link
Author

@AndresCidoncha thanks for the suggested solution.

@bariman
Copy link

bariman commented Jan 26, 2018

@tomdottom do you have '/bin/bash' as Shell executable command on Jenkins->Configure System page? In this case '/bin/sh' should fix it.

@jlccx-incontact
Copy link

I had the same problem, and it was caused because the format of the bash script was incorrect.
I noticed it when I tried to run my script on my local computer and I saw the error message:

/bin/sh^M: bad interpreter: No such file or directory.

After to fix this issue my script was executed successfully.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants