无法在docker agent中运行sh步骤:找不到script.sh

时间:2017-07-06 13:28:39

标签: jenkins jenkins-pipeline

尝试运行以下声明性管道时:

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

我收到错误:

[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

在管道@tmp目录运行时,我可以看到script.sh在短时间内创建。当管道尝试在正在运行的容器中执行它时,我无法判断它是已创建还是已被删除。

一些系统细节

Jenkins作为安装了docker的单节点系统运行。

Jenkins v2.60.1
(all plugins fully updated)

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

1 个答案:

答案 0 :(得分:2)

具有相同的设置(EC2实例上的单个Jenkins 2.73.1主机,不在容器内,使用Docker 17.09.0-ce)和具有声明性和脚本化管道的相同行为。 如果指定

,它会尝试在主机上运行脚本
sh 'sh ./yourscript.sh'

sh './yourscript.sh'

而不是sh 'script.sh'