[英]Jenkins pipeline is unable to terminate a docker container
I have a docker container that performs some tasks and is scheduled inside Jenkins pipeline like this: 我有一个执行某些任务的Docker容器,它在Jenkins管道内进行调度,如下所示:
pipeline {
stages {
stage('1') {
steps {
sh "docker run -i --rm test"
}
}
}
}
If the pipeline is aborted somehow, by timeout or manually for example, the container won't stop and stays alive. 如果管道由于某种原因中止(例如通过超时或手动终止),则容器将不会停止并保持活动状态。
How do I configure it to be terminated along with pipeline? 如何配置它与管道一起终止?
Docker version 17.06-ce
Hi Elessar you can configure an "always" in the post steps. 嗨,Elessar,您可以在发布步骤中配置“始终”。 Mainly it will run the command inside always without depending on the build cancelation, fail or success. 主要是它将始终在内部运行命令,而不取决于构建取消,失败或成功。
pipeline {
agent any
stages {
stage('Example') {
steps {
sh "docker run -i --rm test"
}
}
}
post {
always {
sh "docker stop test" //or something similar
}
}
}
I hope this solve your problem! 希望这能解决您的问题!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.