I'm trying to generate test coverage report and view on teamcity after my project build is complete. So far I have been able to make it work on my local machine (windows) without any issue. The report is generating and I am able to view the coverage reports (html files generated) but it is failing on teamcity (project building with linux agent) with the error below:
Error: System.AggregateException: One or more errors occurred. (Exec format error)
---> System.ComponentModel.Win32Exception (8): Exec format error
at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at Cake.Core.IO.ProcessRunner.Start(FilePath filePath, ProcessSettings settings) in C:\projects\cake\src\Cake.Core\IO\ProcessRunner.cs:line 67
at Cake.Core.Tooling.Tool`1.RunProcess(TSettings settings, ProcessArgumentBuilder arguments, ProcessSettings processSettings) in C:\projects\cake\src\Cake.Core\Tooling\Tool.cs:line 215
at Cake.Core.Tooling.Tool`1.Run(TSettings settings, ProcessArgumentBuilder arguments, ProcessSettings processSettings, Action`1 postAction) in C:\projects\cake\src\Cake.Core\Tooling\Tool.cs:line 101
at Cake.Core.Tooling.Tool`1.Run(TSettings settings, ProcessArgumentBuilder arguments) in C:\projects\cake\src\Cake.Core\Tooling\Tool.cs:line 81
at Cake.Common.Tools.ReportGenerator.ReportGeneratorRunner.Run(IEnumerable`1 reports, DirectoryPath targetDir, ReportGeneratorSettings settings) in C:\projects\cake\src\Cake.Common\Tools\ReportGenerator\ReportGeneratorRunner.cs:line 66
at Cake.Common.Tools.ReportGenerator.ReportGeneratorAliases.ReportGenerator(ICakeContext context, IEnumerable`1 reports, DirectoryPath targetDir, ReportGeneratorSettings settings) in C:\projects\cake\src\Cake.Common\Tools\ReportGenerator\ReportGeneratorAliases.cs:line 151
at Cake.Common.Tools.ReportGenerator.ReportGeneratorAliases.ReportGenerator(ICakeContext context, String pattern, DirectoryPath targetDir, ReportGeneratorSettings settings) in C:\projects\cake\src\Cake.Common\Tools\ReportGenerator\ReportGeneratorAliases.cs:line 71
at Submission#0.ReportGenerator(String pattern, DirectoryPath targetDir, ReportGeneratorSettings settings) in :line 356
at Submission#0.<<Initialize>>b__0_4() in /opt/buildagent/work/[some folder]/build.cake:line 150
at Cake.Core.CakeTaskBuilderExtensions.<>c__DisplayClass29_0.<Does>b__0(ICakeContext context) in C:\projects\cake\src\Cake.Core\CakeTaskBuilder.Execution.cs:line 26
at Cake.Core.CakeTaskBuilderExtensions.<>c__DisplayClass32_0.<Does>b__0(ICakeContext x) in C:\projects\cake\src\Cake.Core\CakeTaskBuilder.Execution.cs:line 83
at Cake.Core.CakeTask.Execute(ICakeContext context) in C:\projects\cake\src\Cake.Core\CakeTask.cs:line 125
at Cake.Core.DefaultExecutionStrategy.ExecuteAsync(CakeTask task, ICakeContext context) in C:\projects\cake\src\Cake.Core\DefaultExecutionStrategy.cs:line 87
at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 336
at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 361
at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 369
at Cake.Core.CakeEngine.RunTask(ICakeContext context, IExecutionStrategy strategy, CakeTask task, String target, Stopwatch stopWatch, CakeReport report) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 284
at Cake.Core.CakeEngine.RunTargetAsync(ICakeContext context, IExecutionStrategy strategy, ExecutionSettings settings) in C:\projects\cake\src\Cake.Core\CakeEngine.cs:line 247
at Cake.Scripting.BuildScriptHost.RunTargetAsync(String target) in C:\projects\cake\src\Cake\Scripting\BuildScriptHost.cs:line 47
at Cake.Core.Scripting.ScriptHost.RunTarget(String target) in C:\projects\cake\src\Cake.Core\Scripting\ScriptHost.cs:line 191
at Submission#0.<<Initialize>>d__0.MoveNext() in /opt/buildagent/work/[some folder]/build.cake:line 346
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Scripting.Script`1.RunSubmissionsAsync(ScriptExecutionState executionState, ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, Func`2 catchExceptionOpt, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at Cake.Scripting.Roslyn.RoslynScriptSession.Execute(Script script) in C:\projects\cake\src\Cake\Scripting\Roslyn\RoslynScriptSession.cs:line 136
at Cake.Core.Scripting.ScriptRunner.Run(IScriptHost host, FilePath scriptPath, IDictionary`2 arguments) in C:\projects\cake\src\Cake.Core\Scripting\ScriptRunner.cs:line 219
at Cake.Commands.BuildCommand.Execute(CakeOptions options) in C:\projects\cake\src\Cake\Commands\BuildCommand.cs:line 41
at Cake.CakeApplication.Run(CakeOptions options) in C:\projects\cake\src\Cake\CakeApplication.cs:line 45
at Cake.Program.Main() in C:\projects\cake\src\Cake\Program.cs:line 80
Process exited with code 1
I tried with dotnet-reportgenerator-globaltool as well, encountered same error. I also specified the ToolPath for ReportGenerator to run using the .dll instead of .exe for both ReportGenerator and dotnet-reportgenerator-globaltool, still no luck.
Please find part of my cake script below:
#tool nuget:?package=ReportGenerator
#addin nuget:?package=Cake.Coverlet
// define variables
...
Task("Test")
.Does(() =>
{
var resultsFolder = Directory(@".\coverage\");
if (testProjectFiles != null)
{
var settings = new DotNetCoreTestSettings
{
Configuration = "Release"
};
foreach (var projectFile in testProjectFiles)
{
var coverletSettings = new CoverletSettings {
CollectCoverage = true,
CoverletOutputFormat = CoverletOutputFormat.opencover,
CoverletOutputDirectory = resultsFolder,
CoverletOutputName = $"{projectFile.GetFilenameWithoutExtension()}.opencover.xml",
};
Information("Running tests in {0}", projectFile.GetFilenameWithoutExtension());
DotNetCoreTest(projectFile.ToString(), settings, coverletSettings);
}
}
else
{
Warning("No unit tests found in the solution!");
}
});
Task("GenerateCoverageReport")
.Does(() =>
{
// Generate test coverage report
var reportGeneratorSetting = new ReportGeneratorSettings{
Verbosity = ReportGeneratorVerbosity.Verbose
};
// ---> failing on teamcity
ReportGenerator("./coverage/*.xml", "./coverage", reportGeneratorSetting);
});
Is there anything I'm missing for the ReportGenerator to run on teamcity? Please advise.
Try using the dotnet tool package instead:
#module nuget:?package=Cake.DotNetTool.Module&version=0.4.0
#tool dotnet:?package=dotnet-reportgenerator-globaltool&version=4.6.7
Then invoke Cake twice, first to bootstrap the module:
dotnet cake --bootstrap --verbosity=verbose && dotnet cake --verbosity=verbose