- GitHub
- AWS CodeBuild
- C# (dotnet 5)
We have a CI/CD pipeline in AWS, our solution has 50 csproj, this solution has 21 AWS lambdas and the rest are shared projects used by the lambdas.
Our problem is that the build is taking about 18 minutes, and most of that time is sonar analyzing the same projects for each of our lambdas, the structure of our buildspec.yml is something like this:
- dotnet tool install --global dotnet-sonarscanner --version 5.2
- dotnet restore --disable-parallel --verbosity m src/MySolution.sln --configfile src/.Nuget/NuGet.config /property:Configuration=Release
- >-
dotnet sonarscanner begin
/k:"something"
/n:"something"
/v:"$API_VERSION"
/o:"something"
/d:"sonar.cs.vstest.reportsPaths=src/test-results/something.trx"
/d:"sonar.cs.opencover.reportsPaths=src/test-results/**/coverage.opencover.xml"
/d:"sonar.host.url=https://sonarcloud.io"
/d:"sonar.login=$SONAR_TOKEN"
/d:"sonar.sources=src"
/d:"sonar.language=cs"
/d:"sonar.branch.name=$BRANCHNAME"
/d:"sonar.sourceEncoding=UTF-8"
- dotnet publish --no-restore -c Release -o Outout src/Code/Lambda.csproj
-- repeat this 20 times for each lambda
- >-
dotnet test
--no-restore
--configuration Release
--logger "trx;LogFileName=something.trx"
--collect:"XPlat Code Coverage"
--results-directory src/test-results
/p:CollectCoverage=true
/p:ExcludeByAttribute=ExcludeFromCodeCoverage
/p:Threshold=100
/p:ThresholdType=\"Method,Line,Branch\"
--settings runsettings.xml
src/Tests/UnitTests.csproj
- >-
dotnet sonarscanner end
/d:"sonar.login=$SONAR_TOKEN"
We googled and found a parameter to exclude commands from sonar, but after the change the code coverage is 0%, we modified the buildspec to something like this:
- dotnet tool install --global dotnet-sonarscanner --version 5.2
- dotnet restore --disable-parallel --verbosity m src/MySolution.sln --configfile src/.Nuget/NuGet.config /property:Configuration=Release
- >-
dotnet sonarscanner begin
/k:"something"
/n:"something"
/v:"$API_VERSION"
/o:"something"
/d:"sonar.cs.vstest.reportsPaths=src/test-results/something.trx"
/d:"sonar.cs.opencover.reportsPaths=src/test-results/**/coverage.opencover.xml"
/d:"sonar.host.url=https://sonarcloud.io"
/d:"sonar.login=$SONAR_TOKEN"
/d:"sonar.sources=src"
/d:"sonar.language=cs"
/d:"sonar.branch.name=$BRANCHNAME"
/d:"sonar.sourceEncoding=UTF-8"
- dotnet build --no-restore -c Release -o Discard src/MySolution.sln
- >-
dotnet test
--no-restore
--configuration Release
--logger "trx;LogFileName=something.trx"
--collect:"XPlat Code Coverage"
--results-directory src/test-results
/p:CollectCoverage=true
/p:ExcludeByAttribute=ExcludeFromCodeCoverage
/p:Threshold=100
/p:ThresholdType=\"Method,Line,Branch\"
--settings runsettings.xml
src/Tests/UnitTests.csproj
- >-
dotnet sonarscanner end
/d:"sonar.login=$SONAR_TOKEN"
- dotnet publish --no-restore -p:SonarQubeTargetsImported=true -c Release -o Output src/Lambda.csproj
-- repeat this 20 times for each lambda
What are we missing to avoid sonar to analyze multiple times the projects and have code coverage of our unit tests?
Thanks for your time.
Juan Zamudio