My current workaround is to create a copy of the nuget.config
with a packageSourceCredentials
section that contains placeholders for user name and password. I then replace my existing nuget.config
with this file and replace the user name and password with environment variables.
The only drawback is that I need to keep both config files in sync. If I modify my nuget.config
in the project I need to remember to update the copy as well.
nuget.config.template
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="GitHub private registry" value="https://nuget.pkg.github.com/your_orga/index.json" />
</packageSources>
<packageSourceCredentials>
<GitHub_x0020_private_x0020_registry>
<add key="Username" value="USER" />
<add key="ClearTextPassword" value="PW" />
</GitHub_x0020_nuget_x0020_registry>
</packageSourceCredentials>
</configuration>
Dockerfile
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-image
ARG NUGET_AUTH_TOKEN
ARG NUGET_USER_NAME
WORKDIR /app
COPY ./My.Project .
# Replace nuget.config
RUN rm nuget.config
COPY ./gitlab-ci/nuget.config.template ./nuget.config
RUN sed -i -e "s/USER/$NUGET_USER_NAME/g" -e "s/PW/$NUGET_AUTH_TOKEN/g" nuget.config
RUN dotnet restore
.gitlab-ci.yml
docker build
--build-arg NUGET_USER_NAME=$NUGET_USER_NAME
--build-arg NUGET_AUTH_TOKEN=$NUGET_AUTH_TOKEN
--tag $CI_REGISTRY/organization/application:$CI_COMMIT_SHA
--file gitlab-ci/Dockerfile
.