<p>Given a registry with several tags for an image, e.g.:</p>

<pre><code>myimage  0.0.3              
myimage  0.0.2              
</code></pre>

<p>Can I somehow extract <code>0.0.3</code> (or rather the most recent tag) into a variable in bash?<br>
I'd like to find out this value so that I could then <code>tagValue++</code> it and use it in a Jenkins pipeline for actions such as:</p>

<ul>
<li><code>docker build</code> to build the next image with an updated tag</li>
<li><code>docker push</code> to push this new image tag to the registry</li>
<li><code>kubectl set image</code> to update a Kubernetes cluster with pods, using the updated image tag</li>
</ul>

<p>Of course, if anyone has a better strategy I am all for hearing it!  </p>

<p>Alternatives:</p>

<ul>
<li><p>Get the value from the Kubernetes Deployment's YAML file, then run the actions above, update the file with the updated tag and push the updated file back to the repository?</p></li>
<li><p>Same as the alternative above, but use <code>kubectl replace</code> instead of <code>kubectl set image</code>? (<a href="https://vishh.github.io/docs/user-guide/kubectl/kubectl_replace/" rel="nofollow noreferrer">example here</a> from the docs)</p></li>
</ul>

<p>we use this with an inhouse v2 docker registry. it depends on jq, so it may not be the right fit for you. the registry seems to return them in the order in which they were added, so we just grab the latest, which is quite possible with jq, if you have a new enough version:</p>

<pre><code>tags_url="https://hot.registry.example.com/v2/somerepoprefix/${repo}/tags/list"
newest_tag=$(curl $tags_url | jq -r '(.tags | reverse)[0]')
</code></pre>
