Hi @James Hizon ,
I have seen the previous question conversation and providing the below response to help with the issue of missing environment variables.
One thing you can try is passing the environment variables when defining the pipeline YAML, you can include the variables and check they are passed as build arguments to Docker. This way, when the image is built, it already has the required variables embedded. In your azure-pipelines.yml
variables:
DATABASE_URL: $(DATABASE_URL)
API_KEY: $(API_KEY)
steps:
- task: Docker@2
inputs:
command: 'buildAndPush'
repository: '<your-acr-name>.azurecr.io/<your-image-name>'
dockerfile: '**/Dockerfile'
containerRegistry: '<your-acr-service-connection>'
tags: 'latest'
arguments: '--build-arg DATABASE_URL=$(DATABASE_URL) --build-arg API_KEY=$(API_KEY)'
If you haven't already, make sure that DATABASE_URL
and API_KEY
are actually defined in Azure DevOps under the pipeline variables section. You can find this by going into your pipeline in Azure DevOps, clicking "Edit," navigating to the "Variables" tab, and adding them there.

Add variables.

Theres is another approach using a .env
file. Instead of manually passing variables in the pipeline, the build process can pull them from a file. You can generate this file dynamically in the pipeline.
- script: echo "DATABASE_URL=$(DATABASE_URL)\nAPI_KEY=$(API_KEY)" > .env
displayName: 'Create .env file'
- task: Docker@2
inputs:
command: 'buildAndPush'
repository: '<your-acr-name>.azurecr.io/<your-image-name>'
dockerfile: '**/Dockerfile'
containerRegistry: '<your-acr-service-connection>'
tags: 'latest'
arguments: '--env-file .env'
If you want to modify the Dockerfile to handle this use ARG
for build-time variables and ENV
for runtime variables.
ARG DATABASE_URL
ARG API_KEY
ENV DATABASE_URL=$DATABASE_URL
ENV API_KEY=$API_KEY
RUN echo "Database URL: $DATABASE_URL"
RUN echo "API Key: $API_KEY"
Hope it helps!
Please do not forget to click "Accept the answer” and Yes
wherever the information provided helps you, this can be beneficial to other community members.

If you have any other questions or still running into more issues, let me know in the "comments" and I would be happy to help you.