destroying container after build success

0 votes
i have created a jenkins master and slave images in docker and spinned those images. both the containers are running. i have pushed them in my private registry. here the scenario is i have to take them in jenkins pipieline script both master and slave.agent should be the slave here, and then the the code should get cloned from git repository after that the image should build, next the container should get destroyed after the build success. for this i need a pipeline script.
Jan 16, 2019 in DevOps Tools by anonymous

recategorized Jan 16, 2019 by Vardhan 311 views
hey, did Hannah's suggestion work?

1 answer to this question.

0 votes


Define your pipeline to clone the git code, build your image and then destroy the image post-always. To delete your containers after build you need to define a variable container outside the pipeline and the use it anywhere inside the pipeline to either start or stop the container. 

def container
pipeline {   
  agents if any
node {
    checkout scm
    docker.withRegistry('', 'credentials-id') {
        def customImage ="my-image:${env.BUILD_ID}")        ​
        container ="-d -u 0:0 -v ")
        /* Push the container to the custom Registry */
post {
        always {
            script {
answered Jan 17, 2019 by Hannah
• 18,570 points

Related Questions In DevOps Tools

0 votes
2 answers
0 votes
1 answer

how to fix the build with maven in bluemix

As per Bluemix Status Page today DevOps Delivery Pipeline ...READ MORE

answered Jul 6, 2018 in DevOps Tools by Kalgi
• 52,370 points
0 votes
1 answer

Build error in TF build definition

I think the problem is in your ...READ MORE

answered Aug 3, 2018 in DevOps Tools by ajs3033
• 7,280 points
0 votes
2 answers

Can Jenkins detect and build new tags from Git repository?

Yes, this can be done in 3 ...READ MORE

answered Jun 24, 2019 in DevOps Tools by Neel
• 3,020 points
+1 vote
1 answer

i have a pyhton code in my git/git repository how to build that code in jenkins

Follow these steps @Bhaskar: Step 1: Open the Jenkins ...READ MORE

answered Oct 14, 2019 in DevOps Tools by Kalgi
• 52,370 points
+5 votes
7 answers

Docker swarm vs kubernetes

Swarm is easy handling while kn8 is ...READ MORE

answered Aug 27, 2018 in Docker by Mahesh Ajmeria
+2 votes
1 answer