Setting ENV in pipeline

Copper Contributor

We have a devops setup where when we set a new tag in Azure Repos, it sets off a docker image build in Azure pipelines and passes the image over to Docker Hub. I have been asked to automate the final part which then automatically loads the latest version of the image to a test environment, which I have achieved using a webhook and setting the pipeline to build and push 2 versions of the app, one with the version number set in the Repo tag and another always set to 'latest'. Then, when the latest image is pushed, dockerhub calls the webhook and the test environment will pull down the latest version of this latest tag and load it to a container. So far so good. What I want to do now is when the image is being built in the pipeline, I want to replace the ENV APP_VERSION which we have set in the Dockerfile with a hardcoded value with the $tag set in Repo, this way we will know from the front end which image build  we are running. This $tag is already being used when pushed to dockerhub, I just want to utilise it further so from the front end we know which version of docker image is running (as certain developers do not have access to the backend to see the docker setup). Anyone have any ideas on how to achieve this?

1 Reply
Just an update, I actually managed to figure this out. In the Dockerfile I added the following:
ARG REPO_TAG
ENV APP_VERSION=$REPO_TAG

In the azure-pipeline.yml I added:
arguments: --build-arg REPO_TAG=$(tag)

This then placed the Repo tag in the ARG REPO_TAG and then on build this REPO_TAG variable was placed into the ENV APP_VERSION on build of the image.