<p>My team developing a kubernetes app in Gitlab using Helm. As part of our review process we deploy an instance of our app into a namespace on MR. Docker images are built and tagged either as latest (for current master stable) or with the branch of the changes.</p>
<p>I would like for the review app to automatically use the latest of the branch <strong>if it exists</strong> else use latest, hopefully without needing intervention to modify the image tags by hand.</p>
<p>What is the cleanest way to do this? I've looked a number of places</p>

VV1
<p>You can pass docker image tag value when deploying helm using <code>--set</code>. So for different branches - master and non-master - in a pipeline you can have different stages where in one you'll pass <code>--set dockerImageTag=latest</code> and for MR branches it'll be <code>--set dockerImageTag=&lt;branch-name&gt;</code>.</p>
<pre><code>mr-build-deploy:
  only:
    - merge_requests
  script:
    - docker build ...
    - docker tag &lt;docker-tag-name&gt;
    - helm install --set dockerImageTag=&lt;docker-tag-name&gt; ...
 ...

master-build-deploy:
  only:
    - master
  script:
    - docker build ...
    - docker tag latest
    - helm install --set dockerImageTag=latest ...
 ...
</code></pre>
<p>Or in <code>values.yaml</code> for the lem chart you can set default value of <code>dockerImageTag</code> to latest so for master step you won't need to specify it.</p>
<p>Speaking of best practices it's not recommended to use latest tag, rather use version number (for example in a form of <a href="https://semver.org" rel="nofollow noreferrer">SemVer</a>) it so you're sure which changes in docker image broke the app if it happens.</p>
