Remove docker image after push in Jenkins scripted pipeline

Viewed 1148

I am build a docker image with the Docker Jenkins plugin and after I push it I would like to delete it. Is there a possibility to use the plugin instead of "sh" commands?

I am aware that I can do sh "docker rmi" but I would like to use the plugin as I use it for build.

Here are the steps so far:

    stage("Docker Build&Push") {
        dir("workingdir/dcd") {
            def image 
            docker.withRegistry("https://${registry}", "${credentials}") {    
                image = docker.build('myImage')
                image.inside {
                    sh 'echo "Hello workld! This is my Docker image"'
                }

                image.push("${version}")
                
                //image.delete() ????
            }
        }
   }

Thank you!

0 Answers
Related