Failed to run sh steps inside docker agent: script.sh Not found

When trying to run the following declarative pipeline:

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

      

I am getting 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

      

While monitoring the piping catalog @tmp

while it is running, I see script.sh

it created for a short period. I can't tell if it was created or has already been deleted when the pipeline tries to execute it in a running container.

some system details

Jenkins runs as the only node system that has docker installed.

Jenkins v2.60.1
(all plugins fully updated)

docker --version
Docker version 17.06.0-ce, build 02c1d87

      

+3


source to share


1 answer


Same settings (one Jenkins 2.73.1 host per EC2 instance, not inside a container, with Docker 17.09.0-ce) and the same behavior with both declarative and scripting. It tries to run the script on the host itself if you specify

sh 'sh ./yourscript.sh'

      

or



sh './yourscript.sh'

      

instead sh 'script.sh'

+2


source







All Articles