Janeth Fernando
Janeth Fernando

Reputation: 104

Iterate groovy map of maps with shell scripting

I have a groovy map which has an object(docker image) as the key and an array of values(docker tags for that docker object)

image_map = [obj_img_1: ['tag1','tag2'], obj_img_2: ['tag_x','tag_y']]

Now I want to iterate this groovy map where I can only get the tags as a shell script so I can do the following iteration

for image of images do
 for tag of tags do
   docker rmi $image:$tag
 done
done

Upvotes: 0

Views: 528

Answers (1)

cfrick
cfrick

Reputation: 37008

Iterate the map, iterate the tags:

image_map.each{ image, tags ->
    tags.each{ tag ->
        ["docker", "rmi", "${image}:${tag}"].execute()
    }
}

Upvotes: 2

Related Questions