I am having private feed in azure devops and trying to do dotnet restore inside the docker file its not working
I have attached the Dockerfile for reference
FROM mcr.microsoft.com/dotnet/aspnet:6.0-alpine AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
WORKDIR /src
COPY Nuget.config /src/
COPY Project/ /src/Project/
WORKDIR "/src/Project"
ARG FEED_ACCESSTOKEN
ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS="{\"endpointCredentials\": [{\"endpoint\":\"https://pkgs.dev.azure.com/OrgName/_packaging/FeedName/nuget/v3/index.json\", \"username\":\"docker\", \"password\":\"${FEED_ACCESSTOKEN}\"}]}"
RUN echo "Environment variables: VSS_NUGET_EXTERNAL_FEED_ENDPOINTS"
RUN echo $VSS_NUGET_EXTERNAL_FEED_ENDPOINTS
RUN apk --no-cache add curl
RUN sh -c "$(curl -fsSL https://aka.ms/install-artifacts-credprovider.sh)"
RUN dotnet restore "Project.csproj" --configfile /src/Nuget.config --verbosity detailed
RUN dotnet build "Project.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Project.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Project.dll"]
I am using azure pipeline with these tasks which works and
- task: NuGetAuthenticate@1
displayName: 'Authenticate to Artifacts'
inputs:
nuGetServiceConnections: 'ServiceName'
- task: DotNetCoreCLI@2
displayName: 'dotnet Restore'
condition: ne(variables['CacheRestored'],'true')
inputs:
command: 'restore'
projects: '**/*$(projectName).csproj'
arguments: '-r win-x64'
nugetConfigPath: 'nuget.config'
feedsToUse: config
using the below code to do docker build which is not working
- task: NuGetAuthenticate@1
displayName: 'Authenticate to Artifacts'
inputs:
nuGetServiceConnections: 'ServiceName'
- task: Docker@2
displayName: 'Build image'
inputs:
command: 'build'
Dockerfile: '**/Dockerfile'
arguments: '--build-arg FEED_ACCESSTOKEN=$(VSS_NUGET_ACCESSTOKEN)'
I have tried to debug the issue by adding --verbosity detailed to dotnet restore and found that and i am getting the following message in pipeline
[CredentialProvider]VstsBuildTaskServiceEndpointCredentialProvider - IsRetry: True [CredentialProvider]VstsBuildTaskServiceEndpointCredentialProvider - Found credentials for endpoint https://pkgs.dev.azure.com/OrgName/_packaging/FeedName/nuget/v3/index.json [CredentialProvider]Sending response: 'Request' 'GetAuthenticationCredentials'. Time elapsed in ms: 0 [CredentialProvider]Time elapsed in milliseconds after sending response 'Request' 'GetAuthenticationCredentials': 0 1>/src/directory/Project.csproj : error NU1301: Unable to load the service index for source https://pkgs.dev.azure.com/OrgName/_packaging/FeedName/nuget/v3/index.json.
I am not sure why after Found credentials for endpoint i am getting error Unable to load the service index for source
I solved the issue by doing Nuget restore and build with dotnet cli and copying the build files to docker. The NuGetAuthenticate@1 task does work outside docker.