简体   繁体   中英

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:

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. 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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM