Jenkins不等待docker exec命令完成 [英] Jenkins does not wait for docker exec command to complete

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

问题描述

这里是情况:

我有一个docker容器(詹金斯)。我已将套接字安装到容器上,以便可以在jenkins容器内执行docker命令。

I have a docker container (jenkins). I've mounted the sockets to my container so that I can perform docker commands inside my jenkins container.

手动,一切都在容器中进行。但是,当詹金斯执行作业时,它不会等待 docker exec 命令执行完毕。

Manually, everything works in the container. However, when Jenkins executes the job, it doesn't "wait" for the docker exec command to run to completion.

下面是Jenkinsfile的摘录。短暂的 printenv 命令正确运行,并打印环境变量。仅运行下一个命令(python),然后Jenkins立即继续前进,而无需等待完成。 Jenkins代理(从属)在Ubuntu映像上运行。在Jenkins外部运行所有这些命令,按预期方式工作。

Below, is an extract from the Jenkinsfile. The short-lived printenv command runs correctly, and prints the environment variables. The next command (python) just gets run and then Jenkins moves on immediately, not waiting for completion. The Jenkins agent (slave) is running on an Ubuntu image. Running all these commands outside Jenkins work as expected.

echo "Running the app docker container in detached tty mode to keep it up"
docker run --detach --tty --name "${CONTAINER_NAME}" "${IMAGE_NAME}"

echo "Listing environment variables"
docker exec --interactive "${CONTAINER_NAME}" bash -c "printenv"

echo "Running test coverage"
docker exec --interactive "${CONTAINER_NAME}" bash -c "python -m coverage run --source . --branch -m pytest -vs"

似乎与这个问题

请任何人解释如何让Jenkins等待 docker exec 命令完成,然后再继续下一步。

Please can anyone explain how to get Jenkins to wait for the docker exec command to complete before proceeding to the next step.

已经考虑了替代方案,例如Docker Pipeline插件,但更喜欢使用与我现有的接近的替代品

Have considered alternatives, like the Docker Pipeline Plugin, but would much prefer to use something close to what I have above where possible.

好,我尝试使用Docker Pipeline插件此处

Ok, another approach, I've tried using Docker Pipeline plugin here.

推荐答案

您可以使用 docker.sock 作为卷装入,在您的 docker-compose中协调主机上的容器。 yml

You can use docker.sock as volume mount to orchestrate containers on your host machine like this in your docker-compose.yml

volumes:
  - /var/run/docker.sock:/var/run/docker.sock

根据您的设置,您可能需要运行

Depending on your setup you might need to run

chmod 666 /var/run/docker.sock

获得第一名。

这在macOS和Linux上均可。

This works on macOS as well as Linux.

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

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