Search code examples
azure-devopsazure-pipelinesnuget-packagenuget-package-restoreazure-artifacts

Flaky "dotnet restore" fails randomly in Azure Pipeline


We use Azure pipelines to build a .NET6 project. Recently, we switched build agents (and organisation) for our pipelines. We've seemingly adjusted for this, but our pipelines fail about 20-70% (seems to vary a lot) of the time on the dotnet restore step:

      - task: DotNetCoreCLI@2
    displayName: "dotnet restore"
    inputs:
      command: "restore"
      projects: "**/Company.Project.sln"

The errors we get are of this kind:

The plugin credential provider could not acquire credentials. Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet`  

error NU1301: Unable to load the service index for source {source outside our new organisation} (many of these)

We specify nuget source in nuget.config. It links to a feed in Azure Devops (Artifacts). Our feed includes the sources that the errors say are missing. It's always warning about sources outside our organisation.

This is our nuget.config

    <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <!-- remove any machine-wide sources with <clear/> -->
    <clear />
    <add key="ProjectName" value="https://pkgs.dev.azure.com/organisationname/ProjectName/_packaging/RepoName/nuget/v3/index.json" />
  </packageSources>
</configuration>

Our feed, project and repo have the same name, so nevermind if I messed up the name substitution.

Things I've tried:

  • add --interactive to dotnet restore
  • add '--no-cache' to dotnet restore
  • add a NuGetAuthenticate@1 step above dotnet restore
  • add a PAT in the nuget config with the packageSourceCredentials tags
  • likely more I'm forgetting

Any other tips are greatly appreciated. Been stuck on getting consistent successful builds for some time now.


Solution

  • To any sorry soul who stumbles upon this. It finally works consistently after adding these to to the dotnet restore step

          feedsToUse: select
          vstsFeed: X/Y
          includeNuGetOrg: false