Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure CI Pipeline - DotNetCoreCLI@2 Task error

I developed WebAPI project using .NET Core 3.1.0 and integration tests using XUnit.

I added the below task in Azure DevOps CI Pipeline (azure-pipelines.yaml) to run the integration tests project.

 - task: DotNetCoreCLI@2
   displayName: 'Run API integration tests - $(buildConfiguration)'
   inputs:
    command: 'test'
    arguments: '--configuration $(buildConfiguration)'
    publishTestResults: true
    projects: '**/IntegrationTests/IntegrationTests.csproj'

I got the below error during pipeline execution. How to resolve this error?

##[error]Error: The process '/usr/bin/dotnet' failed with exit code 1

##[warning].NET 5 has some compatibility issues with older Nuget versions(<=5.7), so if you are using an older Nuget version(and not dotnet cli) to restore, then the dotnet cli commands (e.g. dotnet build) which rely on such restored packages might fail. To mitigate such error, you can either: (1) - Use dotnet cli to restore, (2) - Use Nuget version 5.8 to restore, (3) - Use global.json using an older sdk version(<=3) to build

Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting

##[error]Dotnet command failed with non-zero exit code on the following projects : /home/vsts/work/1/s/src/IntegrationTests/IntegrationTests.csproj

like image 357
Bhanu Avatar asked Nov 24 '20 12:11

Bhanu


People also ask

How do I add a task group to a pipeline in Azure Devops?

Create a task group Select a sequence of tasks in a build or release pipeline, open the shortcut menu, and then choose Create task group.

Does Azure pipeline support .NET 6?

This button is available in the code repository page itself. Since it is a continuous deployment pipeline, upon every code commit to the Git repo this pipeline deploys the . NET 6 API Code to the Azure app service.

Does Azure pipeline build work with dotnetcorecli?

It all build fine on my dev machine, but the Azure pipeline build fails during the DotNetCoreCLI pack command. I was able to get the build working on after installing .NET Core 3.1 on the build machine using the UseDotNet.

How do I use DotNet core CLI task?

.NET Core CLI task. Use this task in a build or release pipeline to build, test, package, or publish a dotnet application, or to run a custom dotnet command. For package commands, this task supports NuGet.org and authenticated feeds like Package Management and MyGet.

How do I configure Azure-pipelines for core Azure?

When the Configure tab appears, select ASP.NET Core. When your new pipeline appears, take a look at the YAML to see what it does. When you're ready, select Save and run. You're prompted to commit a new azure-pipelines.yml file to your repository. After you're happy with the message, select Save and run again.

What is the DotNet restore task in the NET Core pipeline?

The .NET Core task is especially useful to restore packages from authenticated NuGet feeds. This pipeline uses an artifact feed for dotnet restore in the .NET Core CLI task.


1 Answers

I've had a smiller issue but with .netcore 2.2. The problem was that the test tries to build before the test starts restoring the packages for the test, thus fails before the test runs or builds. One thinge that help me overcome this problem was this FAQ:

Most dotnet commands, including build, publish, and test include an implicit restore step. This will fail against authenticated feeds, even if you ran a successful dotnet restore in an earlier step, because the earlier step will have cleaned up the credentials it used. To fix this issue, add the --no-restore flag to the Arguments textbox.

I've also read that the DotNetCLI had some issues when it came to tests like this one here

So I ended up using a script to solve this and other issues related to package restore.

- script: dotnet test '**/IntegrationTests/IntegrationTests.csproj' --configuration $(buildConfiguration) --logger trx;LogFileName=C:\temp\results
  displayName: 'Run API integration tests - $(buildConfiguration)'

I hope that will help you or anyone who has similar issues.

like image 171
Somar Zein Avatar answered Oct 10 '22 19:10

Somar Zein