【问题标题】:Jenkins Docker Pipeline Exit Code -1Jenkins Docker 管道退出代码 -1
【发布时间】:2017-05-07 18:50:17
【问题描述】:

我们有一个 Jenkinsfile,它使用 docker 插件在给定容器中运行脚本。这适用于某些图像,但在其他图像上会立即失败,并出现 -1 退出代码。我们已将错误减少到一个简单的sleep。这是 Jenkins 文件:

node("docker") {
    def wheezy_image = docker.image("pyca/cryptography-runner-wheezy")
    wheezy_image.pull()
    wheezy_image.inside {
        sh """sleep 120"""
    }
}

这是詹金斯的输出

+ docker pull pyca/cryptography-runner-wheezy
Using default tag: latest
latest: Pulling from pyca/cryptography-runner-wheezy
Digest: sha256:ff5d9f661b05d831ace3811eec9f034fed7994279ff2307695a2cb7c32d6fa11
Status: Image is up to date for pyca/cryptography-runner-wheezy:latest
[Pipeline] sh
[3525-VE2ETALXLYB7VN3] Running shell script
+ docker inspect -f . pyca/cryptography-runner-wheezy
.
[Pipeline] withDockerContainer
$ docker run -t -d -u 1000:1000 -w /var/jenkins_home/workspace/3525-VE2ETALXLYB7VN3 --volumes-from 1382a2e208dd5575acd26f11678855282fc854319096de60cef6818ea279f25f -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** --entrypoint cat pyca/cryptography-runner-wheezy
[Pipeline] {
[Pipeline] sh
[3525-VE2ETALXLYB7VN3] Running shell script
+ sleep 120
[Pipeline] }
$ docker stop --time=1 887db8989e03a10dd89132b1ac6e18261ee4a49e6afe8b0c5568326b6c023654
$ docker rm -f 887db8989e03a10dd89132b1ac6e18261ee4a49e6afe8b0c5568326b6c023654
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline

GitHub has been notified of this commit’s build result

ERROR: script returned exit code -1
Finished: FAILURE

有趣的是,如果睡眠时间少于 1 秒,那么它就会过去(但 120 秒的睡眠时间在许多其他图像上都可以正常工作)。

作为参考,这是一个有效的jessie image,一个无效的wheezy image

有谁知道这里可能发生了什么?

【问题讨论】:

标签: docker jenkins jenkins-pipeline


【解决方案1】:

看起来与未安装 ps 的图像有关。我刚刚使用了 debian 基础,并且能够复制它不起作用。安装了ps,果然成功了。您也可以使用 withRun 函数,它可以工作。这是我的 Jenkins 文件:

node("docker") {

    // Weezy that also ran... apt-get update && apt-get install -y procps
    def wheezy_image = docker.image("smalone/weezy-ps-test")
    wheezy_image.pull()
    wheezy_image.inside {
       sh 'sleep 2'
    }

      // Base image for weezy-ps-test that has no ps installed using withRun() instead of inside()
    wheezy_image = docker.image("debian:wheezy")
    wheezy_image.pull()
    wheezy_image.withRun { c ->
       sh 'sleep 2'
    }

    // Base image for weezy-ps-test that has no ps installed
    wheezy_image = docker.image("debian:wheezy")
    wheezy_image.pull()
    wheezy_image.inside {
       sh 'sleep 2'
    }
}

如果 docker 管道插件不存在,我会开一张票。

编辑:有一张票打开,但他们还没有找到根本原因。请参阅:https://issues.jenkins-ci.org/browse/JENKINS-40101 以跟踪此问题的状态!

【讨论】:

  • 就是这样!非常感谢。我期待看到上游的修复,但现在我们可以通过添加 procps(和 Fedora 上的 procps-ng)来解决它。只要 Stack Overflow 允许,我就会奖励赏金(在添加赏金后需要 24 小时后才能奖励)
  • 我的情况,我有点知道为什么会发生错误,并且知道重建图像可以解决它。有没有办法捕获“错误:脚本返回退出代码 1”并在詹金斯作业失败之前再次尝试重建图像??
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-14
相关资源
最近更新 更多