How to Remove Images in Jenkins Shell Script

8/24/2020

Parameter Tagging :

parameters([
    string(name: 'Version_Major', defaultValue: '1', description: 'Version Major'),
    string(name: 'Version_Minor', defaultValue: '0', description: 'Version Minor'),
    string(name: 'Version_Patch', defaultValue: '0', description: 'Version Patch')
])

stage ('Build Docker images') {
        sh "cd /home/admin/file && docker build -t Image_abcdef:${Version_Major}.${Version_Minor}.${Version_Patch} . "

These images are already created on my docker

  • Images Name | Tag
  • Image_abcdef | 1.0.8
  • Image_abcdef | 1.0.7

if I build images, it will automatically delete the last images. It will be like this :

  • Images Name | Tag
  • Image_abcdef | 1.0.9
  • Image_abcdef | 1.0.8

any suggestion for me ?

Thanks before

-- arifin syamsul
devops
docker
jenkins
jenkins-pipeline
kubernetes

0 Answers