Jenkins没有等待Docker命令完成 [英] Jenkins is not waiting for Docker command to finish

查看:56
本文介绍了Jenkins没有等待Docker命令完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让Jenkins在Jenkins从属服务器上的docker中运行以下命令:

I'm trying to get Jenkins to run the following command within docker on a Jenkins slave:

docker run -i -v `pwd`:/opt/myapp -w /opt/myapp -t mydockerimage /bin/bash -c "./setup_dev_env.sh && make all"

问题在于,当我在Jenkins中运行此 时,会产生Docker进程,但是Jenkins不等待它,并且立即返回成功。但是,如果我用无限循环替换Docker命令,Jenkins将按预期方式等待。

The trouble is that when I run this from within Jenkins the Docker process is spawned, but Jenkins doesn't wait for it and returns success immediately. If, however, I replace the Docker command with an infinite loop Jenkins will wait, as expected.

当我以Jenkins用户的身份直接从build slave运行此命令时,系统会等待命令完成(这就是我想要发生的事情。)。

When I run this command from the build slave directly, as the Jenkins user, the system waits for the command to finish (which is what I want to happen).

我尝试执行 docker attach ,但这也会立即返回。 docker wait 将使Jenkins等待它,但我看不到任何输出。

I've tried doing a docker attach, but that also returns immediately. docker wait will cause Jenkins to wait for it, but I won't see any of the output.

也许我要解决所有这些错误...

Perhaps I'm going about this all wrong...


  1. 如何让Jenkins等待此命令完成?

  2. 如何让Jenkins显示在Docker容器中运行的命令的输出?

  3. 如何获取在Docker容器中运行的命令的退出代码以设置为让詹金斯可以确定它是成功还是失败?


推荐答案

问题是命令行中的 -t 。删除 -t 会使Jenkins等待docker完成其工作。

It turns out the problem was the -t in the command line. Removing -t caused Jenkins to wait for docker to finish what it was doing.

我有一个预感之所以如此,是因为ttys有时可能很奇怪,并且詹金斯可能正在使用与我在shell提示符下运行相同命令时不同的tty类型(或根本不使用)。

I had a hunch this was the case because ttys can sometimes be strange and Jenkins is probably using a different type of tty (or not at all) than I am when I'm running the same command at the shell prompt.

最后,此命令有效:

docker run -i -v `pwd`:/opt/myapp -w /opt/myapp mydockerimage /bin/bash -c "./setup_dev_env.sh && make all"

这篇关于Jenkins没有等待Docker命令完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆