My requirement is to set few environment variables on the docker image that is built by azure devops pipeline.
This pipeline is used for dev/stage/production environments, each stage is tied to its own set of group variables, these variables I want to be available in nodejs app.
I can read the variables within the pipeline using $VARNAME but cant read same when the code runs using process.env.VARNAME.
I understand that it is not the best approach as the image would have environment variables which may potentially have secrets hence I am open to different ideas as well.
What I have tried so far: Added ARG in dockerfile ARG VARNAME=somevalue on the docker build task added
- task: Docker@2
displayName: Build docker image
inputs:
command: build
repository: $(imageName)
tags: $(Build.BuildId)
buildContext: '$(Pipeline.Workspace)/PublishedWebApp'
arguments: --build-arg SOMEVAR=anewvalue
I try to access this as process.env.SOMEVAR in nodejs code.
I can actually see the --build-arg on the docker build executed in the pipeline but in the code it never appears.
What I am after is pretty standard requirement, we have multiple environments, each environment will have different keys (different group variables tied to different stage), how do I pass different keys to the deployment?
--build-arg STAGE=$(VAR_STAGE)"
- see docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/… - but then you cannot use thebuild_and_push
task but you have to split the build and the push part – kgorskowski