0
votes

I'm tagging my images with git_short_sha and branch_name and some other tags. I'm trying to get the short_sha tag of the image tagged with master using a gcloud command. I've managed to get all tags, or a specific tag by its' location with these commands:

1. gcloud container images list-tags eu.gcr.io/${PROJECT_ID}/${IMAGE} --format='value(tags[1])' --filter="tags=master"

result:
76f1a2a

but I cannot be sure that the second element will always be the short_sha.

 2. gcloud container images list-tags eu.gcr.io/${PROJECT_ID}/${IMAGE} --format='value(tags)' --filter="tags=master"

result:
1.0.0-master,76f1a2a,76f1a2a-master,master

Is it possible to get only the short_sha tag by using only gcloud command?

1

1 Answers

2
votes

Try:

gcloud container images list-tags eu.gcr.io/${PROJECT_ID}/${IMAGE} \
--flatten="[].tags[]" \
--filter="tags=${TAG}"

This came up once before. If you encounter that bug, you can try the jq solution.