5

I have an Azure DevOps project (just one).

I have a Build Pipeline set to run in the "Hosted VS2017" Agent Pool. This Agent Pool appears to be in the [MyProject]\Build Administrators, Contributors, Project Administrators, and Release Administrators roles.

I also have an Artifacts nuget feed in the DevOps project. It has [MyProject]\Project Valid Users set as "Reader" role. It appears that Project Valid Users has all of the Agent Pool's roles mentioned above as members.

I have an azure-pipelines.yml script that adds that adds the artifacts feed as a nuget source right at the beginning:

# Add nuget source
- powershell: Invoke-RestMethod "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile "$env:UserProfile/nuget.exe"
- script: '%UserProfile%\nuget.exe sources Add -Name "devops" -Source "https://pkgs.dev.azure.com/MyProject/_packaging/feed/nuget/v3/index.json"'

The build yml then dot a dotnet build but fails inside NuGet.targets with:

Unable to load the service index for source https://pkgs.dev.azure.com/MyProject/_packaging/feed/nuget/v3/index.json.
Response status code does not indicate success: 401 (Unauthorized).

how can I make this work? My build needs packages from other builds that are on that artifacts feed...

3 Answers 3

8

There is a better alternative imo. You can continue using your script to dotnet restore. Simply add a task just before that with NuGetAuthenticate@0

steps:
- task: NuGetAuthenticate@0
- script: dotnet restore --no-cache --force

this task will authenticate the pipeline with the nuget feeds that require so and are found at the NuGet.config file.

More info here

Notice that when the nuGet feed is within Azure DevOps there is nothing else required. If the feed is external you can configure at your Azure DevOps a nuGet Service Connections (at the link there is further info).

Sign up to request clarification or add additional context in comments.

2 Comments

Many thanks for this, was looking for HOURS how to have Azure Artifacts private feed AND on-premise public feed. Authenticate do the job perfectly
I am using cloud hosted agent and Azure Artifacts feed. After adding NugetAuthenticate task, my problem was solved.
1

Use the built-in tasks for installing and running NuGet and you won't have authentication problems.

1 Comment

dotnet build doesn’t use nuget command line to restore and the behavior of dotnet restore is isn’t reproducible by just running nuget restore. How would I be able to use the nuget task for this?
1

Use the dotnet task's restore command. If you're using a single Azure Artifacts feed, just select it from the dropdown in the task (instead of the PowerShell you mentioned). If multiple feeds (doesn't look like it from your question, but just in case), you'll need to check in a NuGet.config that references all of those feeds, then point the task to that config.

You may also need to pass the '--no-restore' flag to your 'dotnet build' command.

If you still encounter issues, ensure the correct build identity has access to your feed.

10 Comments

I don’t understand what you mean by “just select it from the dropdown in the task“. Why would dotnet restore behave differently than dotnet build which actually just does an implicit restore?
Right now, the only way to tell dotnet about an authenticated feed (i.e. to create a nuget.config that has a <password> field with the build's access token) is to use either the dotnet or the nuget task's restore command. We have on the backlog a "NuGet authenticate" task that would generate that config and leave it around on disk for you to use as part of a scripted invocation of dotnet build or dotnet restore.
Why does dotnet restore work but dotnet build integrated restore not? My understanding is that they are nearly the same in terms of how they work
Would $env:SYSTEM_ACCESSTOKEN not work for my purposes?
dotnet restore and dotnet build call the same code to restore. The difference is in the current implementation of the VSTS dotnet task, which only provides the properly authenticated NuGet.config when you select the 'restore' step.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.