Replies: 2 comments 2 replies
-
I did some more digging and at the time of writing, the buildArgs property does not support environment variable substitution. Source: Microsoft Learn
|
Beta Was this translation helpful? Give feedback.
-
@DeBiese , there is a way to make what you need to work. You will need to use the daily build until For 1.9.4, we added a feature that allows you to reference values from azd-environment config within docker->buildArgs (#4008). This feature is mainly required and used by .Net Aspire projects, but it can be used directly by your project, if you want it. Here's how you can make it work:
buildArgs:
- NUGET_PAT={buildArgs.nugetPat}
{
"buildArgs": {
"nugetPath": "xxxx-xxx-xxx-xx"
}
} Note how each node in the key-path becomes a new level in the azd-env config.
|
Beta Was this translation helpful? Give feedback.
-
I'm trying to use azd deploy in a pipeline in Azure Devops.
My project uses some of our own nuget packages from our private feed.
A docker build step in the pipeline (using Docker@2 with arguments '--build-arg NUGET_PAT=$(myVariableName)' works to build my code.
However, I'm struggling to use my variable from my yml file, through the azure.yaml to Docker when using azd deploy.
I have an azure.yaml file that looks like this:
name: MySolutionName
metadata:
template: [email protected]
services:
api:
project: MyProject.API
host: containerapp
language: dotnet
docker:
path: ./Dockerfile
context: ../
buildArgs:
- NUGET_PAT= [ACTUAL PAT]
In my docker file I do the following:
...
ARG NUGET_PAT
ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS
"{"endpointCredentials": [{"endpoint":"https://somesuch.pkgs.visualstudio.com/_packaging/myNamed_feed/nuget/v3/index.json", "username":"docker", "password":"${NUGET_PAT}"}]}"
RUN curl -L https://raw.githubusercontent.com/Microsoft/artifacts-credprovider/master/helpers/installcredprovider.sh | bash
RUN echo $NUGET_PAT
RUN echo $VSS_NUGET_EXTERNAL_FEED_ENDPOINTS
COPY ["MyProject.API/MyProject.API.csproj", "MyProject.API/"]
COPY NuGet.Config ./
RUN dotnet restore "./MyProject.API/MyProject.API.csproj"
...
When I change my azure.yaml to have the actual value of the PAT instead of [ACTUAL PAT], the build works.
I would however like to use a variable here so that my PAT isn't in the yaml file.
I have tried doing this in my pipeline:
displayName: Build and Deploy Applications
inputs:
azureSubscription: $(DEVOPS_SERVICE_CONNECTION)
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
azd env set NUGET_PAT=$(myVariableName)
azd deploy --no-prompt
With (azure.yaml):
buildArgs:
- NUGET_PAT=$(NUGET_PAT)
But that doesn't work.
The value of the ARG in docker is now "$(NUGET_PAT)" instead of its value, so the restore fails to connect to the private feed.
How would I do this?
Beta Was this translation helpful? Give feedback.
All reactions