2

While running the UnitTest project in Azure build pipeline. I get bellow error:

Restoring NuGet package Microsoft.Portal.TestFramework.UnitTest.6.672.0.5.
  GET https://msazure.pkgs.visualstudio.com/_packaging/ae95f9fe-9452-4aa1-b167-92a7fcfc670f/nuget/v3/flat2/microsoft.portal.testframework.unittest/6.672.0.5/microsoft.portal.testframework.unittest.6.672.0.5.nupkg
  GET https://msazure.pkgs.visualstudio.com/_packaging/d387a8da-063b-4a96-afb8-093924314a98/nuget/v3/flat2/microsoft.portal.testframework.unittest/6.672.0.5/microsoft.portal.testframework.unittest.6.672.0.5.nupkg
  GET https://msazure.pkgs.visualstudio.com/_packaging/ab5b6ade-9b91-4eb5-8dc6-eacc4a5cdda7/nuget/v3/flat2/microsoft.portal.testframework.unittest/6.672.0.5/microsoft.portal.testframework.unittest.6.672.0.5.nupkg
MSBuild auto-detection: using msbuild version '16.8.2.56705' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin'.
  GET https://api.nuget.org/v3-flatcontainer/microsoft.portal.testframework.unittest/6.672.0.5/microsoft.portal.testframework.unittest.6.672.0.5.nupkg
  NotFound https://api.nuget.org/v3-flatcontainer/microsoft.portal.testframework.unittest/6.672.0.5/microsoft.portal.testframework.unittest.6.672.0.5.nupkg 57ms
    [CredentialProvider]Using the ADAL UI  flow for uri https://msazure.pkgs.visualstudio.com/_packaging/Toolset/nuget/v3/index.json. User sign-in required in a pop-up authentication window.

It states that authentication is required.

As per this post How to pass Azure Auth when Deploying NuGet Package via Nuke.Common/NuGet.CommandLine the solution suggested is to "update the expiration date on the password DevOps".

Can anyone tell how can I update the expiration date on the Azure DevOps. I didn't have much reputation to comment in that post so I had to create a new post.

Azhar
  • 107
  • 12

4 Answers4

2

For password in this case, I believe this means PAT or Personal Access Token. For whichever user that token was generated, as that user in Azure Devops, click on user settings -> personal access tokens. Then find the desired token and click edit, then choose a new desired expiration date.

Update: make sure to add the nuget authenticate task in the yaml pipeline definition defined here.

Dan Csharpster
  • 2,662
  • 1
  • 26
  • 50
  • Under user settings, I verified the PAT all the tokens are active and is not expired. Is there any other authorization apart from PAT which is required while running the pipeline in Azure DevOps? – Azhar Dec 23 '20 at 06:19
  • 1
    Maybe we should take a step back and verify some things. This nuget feed is under the same organization as your build pipeline, right? How do you have nuget authentication setup in your pipeline? I think this doc might be able to help you: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/package/nuget-authenticate?view=azure-devops – Dan Csharpster Dec 23 '20 at 15:15
  • Yes, looks like I was missing the nuget authentication. Actually I am using .npmrc file to authenticate npm for restoring nuget. After I added this task into my build pipeline along with the NuGet restore task in the pipeline before running the UnitTest it worked. Thanks! – Azhar Dec 24 '20 at 11:33
  • I'm glad you got it working! If you can go ahead and mark this as the accepted answer, then this question will stop showing up in the unanswered list. I'll update my answer to include the task. – Dan Csharpster Dec 24 '20 at 14:46
1

In the restore task of your pipeline, do you select the following option:

enter image description here

Usually choosing this option does not require authentication.

If you select the second option, you can add a NuGet authenticate task before restore task to configure NuGet tools to authenticate with Azure Artifacts and other NuGet repositories. enter image description here

Besides using the NuGet credential plugin, You can also use the dotnet cli to add credentials to the nuget source.

RUN dotnet nuget add source "your-source-url" --name "source-name" --username "useless" --password "$PAT" --store-password-in-clear-text
RUN dotnet restore

Here is a case you can refer to.

Hugh Lin
  • 17,829
  • 2
  • 21
  • 25
  • I am using the second option 'Feeds in my NuGet.config' because I have NuGet.config file for the UnitTest project for which I want to restore the packages. – Azhar Dec 23 '20 at 14:30
  • 1
    You can try to add a NuGet authenticate task before restore task or use the dotnet cli to add credentials to the nuget source – Hugh Lin Dec 25 '20 at 07:54
1

How to update the expiration date on the password in Azure DevOps

According to the error log, you should make sure you can access the URL:

https://msazure.pkgs.visualstudio.com/_packaging/Toolset/nuget/v3/index.json

This is a feed that requires certain permissions to access. You could open this URL in your browser in private mode to check if you have permission to access with your account.

enter image description here

If you could access that URL, you could try to add following in your nuget.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="MyAzureFeed" value="https://msazure.pkgs.visualstudio.com/_packaging/Toolset/nuget/v3/index.json" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>

  <packageSourceCredentials>
    <MyAzureFeed>
      <add key="Username" value="YouAccount" />
      <add key="ClearTextPassword" value="xxxx(could be your PAT)" />
    </MyAzureFeed>
  </packageSourceCredentials>

</configuration>

If you are using private agent to build the pipeline, you could also update the password in the server directly:

Private NuGet Feed - Remembering Password

Note: Even if I could open that URL in my browser, but I still could not found this package from that feed after I adding that feed source in my Visual Studio as test, could only found the package microsoft.portal.testframework(Not sure if my permissions are insufficient):

enter image description here

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • 1
    Yes, I am able to access the URL. However in my case I cannot add PAT in the nuget.config file as same file is added to the production. The authentication mode here I am using is .npmrc file and after adding this in the build pipeline my build worked. Thank you for detail information. It gave me a more clarity on authentication and now I know that authentication can also be done in nuget.config file. Thank you! – Azhar Dec 24 '20 at 11:56
  • I was able resolve by getting help from the community members. However I posted my final solution which might help other community members. Thanks! – Azhar Dec 28 '20 at 11:43
0

After getting help from the community members, I am posting my final solution which helped me to run the UnitTest in the AzureDevOps build pipeline. The steps which I added before running UnitTests:

  1. Added NuGet restore task
  2. Added NuGet authenticate task

Here is the build pipeline screenshot. enter image description here

Azhar
  • 107
  • 12