运行 ReportGenerator 在 teamcity 上使用 cake 构建(执行格式错误)

Running ReportGenerator using cake build on teamcity (Exec format error)

我正在尝试在项目构建完成后生成测试覆盖率报告并在 teamcity 上查看。到目前为止,我已经能够在我的本地机器 (windows) 上毫无问题地运行它。报告正在生成,我可以查看覆盖率报告(生成 html 个文件),但它在 teamcity 上失败(使用 linux 代理构建项目)并出现以下错误:

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

我也尝试使用 dotnet-reportgenerator-globaltool,遇到同样的错误。 我还指定了 ReportGenerator 的工具路径 运行 使用 .dll 而不是 ReportGenerator 和 dotnet-reportgenerator-globaltool 的 .exe,仍然没有成功。

请在下面找到我的蛋糕脚本的一部分:

#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);
    });

Teamcity 上 运行 的 ReportGenerator 是否缺少任何内容?请指教

尝试改用 dotnet 工具包:

#module nuget:?package=Cake.DotNetTool.Module&version=0.4.0
#tool dotnet:?package=dotnet-reportgenerator-globaltool&version=4.6.7

然后调用 Cake 两次,首先是 bootstrap 模块:

dotnet cake --bootstrap --verbosity=verbose && dotnet cake --verbosity=verbose