Azure devops issue with sonar cloud code coverage - azure

In azure devops build pipeline, I am having the below stages.
Prepare analysis on sonar cloud
dotnet restore
dotnet build
dotnet test
dontnet publish
copy test files .. this for copying (*.trx *.xml) to respective directory.
Run code analysis
Publish quality gate result.
here my pipeline runs successfully with the tests but its not giving code coverage. code coverage showing 0.00%
*.trx file is copying on the required path & I have also tried with the default path of trx file but its giving below message in logs.
ERROR MESSAGE
Post-processing started.
00:23:49.775 Property 'sonar.cs.vstest.reportsPaths' provided, skipping the search for TRX files in default folders.
00:23:49.995 Did not find any binary coverage files in the expected location.
00:23:49.995 Falling back on locating coverage files in the agent temp directory.
00:23:49.995 Searching for coverage files in D:\a\_temp
00:23:49.995 No coverage files found in the agent temp directory.
WARNING: The following projects do not have a valid ProjectGuid and were
not built using a valid solution (.sln) thus will be skipped from
analysis...
D:\a\1\s\Rost.API.Tests\Rost.API.Tests.csproj
I expect the code coverage in the pipeline, currently code coverage showing 0.00%.

May i confirm several questions with you?
Did you add --collect "Code coverage" option to the command line arguments?
Code coverage can be collected by adding --collect "Code coverage"
option to the command line arguments. This is currently only available
on the Windows platform.
If run the test command on local, did the code coverage show correctly?
BTW, SonarQube requires a valid Project GUID but Core projects dont actually use this.It is recommended to add the ProjectGUID in the test project file.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<!-- SonarQube requires a valid Project GUID but Core projects dont actually use this -->
<ProjectGuid>{9C99E491-F56E-4515-9F0B-D72A5207DB13}</ProjectGuid>
</PropertyGroup>
</Project>

Related

Azure CI pipeline ignored my botdetect.xml file

I am using Azure CI pipeline and using the .NetCore build tasks template, today I noticed that the file botdetect.xml in my source control, and after project passes from CI/CD pipeline, specific .xml
dotnet publish command publish the output of your .NET build, you need to make sure the botdetect.xml file exists in your build output, then it can be published to $(Build.ArtifactStagingDirectory) by running dotnet publish --output $(Build.ArtifactStagingDirectory), and publish the artifact by using Publish artifact task.
You could check your .csproj file to see whether the .xml file has been set to "Always Copy To Output Directory", it seems like:
<Compile Include="botdetect.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile>

Compile directory in Azure DevOps Repos and save the results somewhere

Let’s say I have a directory structure like this in an Azure DevOps repo:
Main/
- A/
- *.csproj
- B/
- *.csproj
- C/
- *.csproj
Each subfolder has a .csproj file. I want to compile the Main/A/ folder and save the build results (artifacts?) somewhere, be it a folder or something else. How do I tell Azure to build that precise Main/A/*.csproj file and do I need to use /p:OutputPath inside the VSBuild#1 task, or do I need to use some other Azure task?
How do I tell Azure to build that precise Main/A/*.csproj file and do
I need to use /p:OutputPath inside the VSBuild#1 task
If you're using classic UI, you need to unlink the default solution:
And then choose the A project by the browse option:
If you're using Yaml format, you should use something like solution: A/A.csproj to specify which project to build.
Note:
Since now we're building single project instead of whole solution, we should use Project Configuration instead of Solution Configuration. any cpu is Solution Platform instead of Project Platform(AnyCPU). So we should make sure we're building single project with AnyCPU if we want to build one project with this setting.
If you got error The OutputPath property is not set for project 'A.csproj', that indicates you should use valid project configuration. In your case, if you're using any cpu, change it to AnyCPU.
In addition:
1.To publish the build results as build artifacts for further use. You can use Copy Files task and Publish Build Artifacts task like this:
Copy Files Task.
Publish Build Artifacts
Then you can download the Test.zip in Summary tab from build log page. Also, you can use this artifact in release pipeline by using download artifacts task.
Check this, if you're trying build code project instead of whole solution. You can consider MSBuild Task. They(Msbuild task,VS Build task) both calls msbuild.exe to do the build job.
Hope all above helps :)

how to publish wepback bundles on VSTS for MVC app on azure

I am having trouble figuring out how to use VSTS to deploy an arbitrary directory from my build to an azure web app.
The arbitrary directory is produced during the build step and contains the webpack bundled javascript for my app. Here are the details:
I have an MVC 5 app and I just started using webpack to bundle the output of my typescript files. webpack creates a set of bundles and writes them to $(project_dir)/Scripts/bundles.
All my typescript source are in various other directories under /Scripts as well (App, Api, Lib etc). But from a VS project point of view, bundles is empty, but added to the project.
Everything works great locally. I can do a debug build and webpack-dev-server serves up the bundles. I can do a release build and webpack happily creates the bundles on disk in /Scripts/bundles. And my code happily consumes the bundles.
I have edited the project file to include:
<Content Include="Scripts\Bundles\**" />
and if I do a publish from within visual studio it all works great. But VSTS doesn't seem to recognize this part of the project
We use VSTS to do our building and releasing to azure. I can't for the life of me figure out how to get VSTS to publish this /Scripts/bundles directory.
In my project properties, I created a pre-build step that runs webpack. I know that the files are in the Scripts/bundles directory at the end of the build because the closest I have come to getting this working is to have the VSTS build a second artifact that is the zip file of that bundles directory and the files are in there.
I could solve my problem if I knew one of the following (I think):
how to get an arbitrary directory to show up in the main artifact like the normal build output - I can then use my standard release definition to push it to azure
how to publish a second artifact in a release definition?
If you can solve #2, the issue is that in building the artifact for /Scripts/bundle, it put the contents of the bundle directory in the root of the zip file, rather than having bundle as the root of the zip file. So when I unzip the file, It will have to first create /Scripts/bundle and then unzip.
I must have been entering the wrong search terms when I was first trying to figure out how to do this. Once I hit on the right search terms I found a bunch of articles that talk about how to get "extra files" into the deployment package for Azure.
Here is a good article. I basically followed it and things just worked. I added these lines to my csproj file:
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
WebpackBundles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
<CopyAllFilesToSingleFolderForMsdeployDependsOn>
WebpackBundles;
$(CopyAllFilesToSingleFolderForMsdeployDependsOn);
</CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup>
<Target Name="WebpackBundles">
<ItemGroup>
<_CustomWebPackFiles Include="Scripts\bundles\*" />
<_CustomWebPackFiles Include="Scripts\bundles\**\*" />
<FilesForPackagingFromProject Include="%(_CustomWebPackFiles.Identity)">
<DestinationRelativePath>Scripts\bundles\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
The PropertyGroup was already there. I just inserted the WebpackBundles; call into those two elements and then defined the WebpackBundles target.
And I ended up removing the
<Content Include="Scripts\Bundles\**" />
line and replaced it with the new Target that the article suggests. I am running webpack as a pre-build step only on the release build. I am using webpack-dev-server for the debug build locally. The only change I had to make to our VSTS build was to add two npm steps:
npm install
npm install webpack -g
this allowed the pre-build step to find the webpack executable and run it.
there was no change to the VSTS release definition because the webpack bundles got put into the deployment zip file in the right location.

VSTS test agent is not running test build as X64 bit process, "no matching test is present" error is being displayed

We are running these test as part of VSTS pipline on Azure VM, test agent get deployed successfuly but run function test task fails. we are building whole solution containing test solution as x64 bit
Refer to these steps and check the result:
Create a runsettings file (xml file) to specify TargetPlatform
Code:
<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
<RunConfiguration>
<ResultsDirectory>.\TestResults</ResultsDirectory>
<TargetPlatform>x64</TargetPlatform>
</RunConfiguration>
</RunSettings>
Add it to source control
Specify that file for Run Functional Tests step.
Update:
These are my build steps:
Visual Studio Build
Windows Machine File Copy
Visual Studio Test Agent Deployment
Run Functional Tests

How can I have teamcity run a .bat file on each successful build?

I have a teamcity (4.something) install that creates .wsp file for deployment to sharepoint. Currently I have to copy the wsp out of the build artifacts directory and into a little deploy folder I have created. In the folder I run a .bat that deploys the new .wsp to our test server.
What steps can I take to automate this?
Either copy the .bat into the artifacts folder and update the paths etc or copy from the artifacts folder into the 'deploy' folder and run the .bat from there.
I am a neophyte when it comes to the intricacies (or basics!) of MSBuild and the like... so hand holding is appreciated!
In more recent versions of TeamCity...
In the build definition you can identify artifacts which can be copied/zipped. Artifacts can then be downloaded manually or referenced from another build (Artifact Dependency).
You can setup a 'build configuration' to do your deployment directly from artifacts produced by your ci build.
Create a build to do your deployment
Build Step
Run: Executable with parameters
Command executable: .bat file (make sure it as part of the ci build artifacts generated)
Command parameters: whatever parameters your patch files needs
Dependencies
Add New Artifact dependency
Depend on: select the ci build you want to deploy
GetArtifacts from: Last successful build
Artifact rules: +:**/*.*
So, given artifacts (like your batch file) are in the CI build... You now have a 'deploy' build. When you run it (manually or setup a Build Trigger) it will copy all the CI build artifacts to it's working directory (Artifact Dependency) and then run your batch file to do the deployment.
Pretty slick.
note: just make sure that the account running the TeamCity BuildAgent has permissions to do all the deployment stuff.
Hope this helps somebody as it took me a while to sort this out ;)
I've done this by creating a nant task, and then having TeamCity execute the nant task. It's more of a pain than it should be. You should be able to do the same as a post-build event with MSBuild.

Resources