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
2
Answers
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.
I followed your dockerfile and yaml, confirm it’s working on my side.
Here are some steps and considerations to help you troubleshoot and resolve this issue:
Check the value of
VSS_NUGET_EXTERNAL_FEED_ENDPOINTS
value in the log, it should the correct feed url, and credential.Check on target feed setting, make sure the user has contributor role or above.
Verify the Token
$(VSS_NUGET_ACCESSTOKEN)
, make sure it’s working, you can recreate it for a check.Check NuGet.config, make sure it’s correctly referencing the private feed.