Im trying to use sonarqube from a Frosting cake project.
There are my tasks:
using Cake.Common;
using Cake.Common.IO;
using Cake.Common.Tools.DotNetCore;
using Cake.Common.Tools.DotNetCore.Build;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Docker;
using Cake.Frosting;
using Cake.Git;
using Cake.SemVer;
using Cake.Sonar;
using System.Linq;
public static class Program
{
public static int Main(string[] args)
{
return new CakeHost()
.UseContext<BuildContext>()
.Run(args);
}
}
public class BuildContext : FrostingContext
{
public string MsBuildConfiguration { get; set; }
public string ProjectPath { get; set; }
public string SolutionFile { get; set; }
public string SolutionName { get; set; }
// For SonarQube
public string SonarKey { get; set; }
public string SonarUrl { get; set; }
public string Login { get; set; }
public string Password { get; set; }
public string Verbose { get; set; }
public BuildContext(ICakeContext context)
: base(context)
{
ProjectPath = context.Argument("projectPath", @"C:\Users\User\source\repos\ConsoleApp1");
MsBuildConfiguration = context.Argument("configuration", "Release");
SolutionFile = context.GetFiles($"{ProjectPath}/*.sln").First().GetFilename().ToString();
SolutionName = context.GetFiles($"{ProjectPath}/*.sln").First().GetFilenameWithoutExtension().ToString();
SonarKey = context.Argument("SonarKey", "MyProject");
SonarUrl = context.Argument("SonarUrl", "http://localhost:9000/");
Login = context.Argument("Login", "admin");
Password = context.Argument("Password", "admin");
}
}
[TaskName("Clean")]
[TaskDescription("Clean build solution folder. It depends of value of configuration argument: ./bin/Debug for 'Debug' value or .bin/Release for 'Release' value")]
public sealed class CleanTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var directory = context.Directory($"{context.ProjectPath}/{context.SolutionName}/bin/{context.MsBuildConfiguration}");
context.Log.Information($"Cleaning folder: {directory}");
context.CleanDirectory(directory);
}
}
[TaskName("Restore")]
[TaskDescription("Restore selected project")]
public sealed class RestoreTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var directory = context.Directory($"{context.ProjectPath}/{context.SolutionFile}");
context.Log.Information($"Restoring project: {directory}");
context.DotNetCoreRestore(directory);
}
}
[TaskName("Build")]
[TaskDescription("Build selected project. It depends of value of configuration argument (Debug or Release)")]
[IsDependentOn(typeof(CleanTask))]
[IsDependentOn(typeof(RestoreTask))]
public sealed class BuildTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var directory = context.Directory($"{context.ProjectPath}/{context.SolutionFile}");
context.Log.Information($"Building project: {directory}");
context.DotNetCoreBuild(directory, new DotNetCoreBuildSettings
{
Configuration = context.MsBuildConfiguration,
});
}
}
[TaskName("SonarBegin")]
[TaskDescription("Start test with SonarQube.")]
public sealed class SonarBeginTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var directory = context.Directory($"{context.ProjectPath}/{context.SolutionFile}");
var settings = new SonarBeginSettings
{
Key = context.SonarKey,
Url = context.SonarUrl,
Login = context.Login,
Password = context.Password,
WorkingDirectory = directory,
Verbose = true,
};
context.SonarBegin(settings);
}
}
[TaskName("SonarEnd")]
[TaskDescription("End test with SonarQube.")]
public sealed class SonarEndTask : FrostingTask<BuildContext>
{
public override void Run(BuildContext context)
{
var settings = new SonarEndSettings
{
Login = context.Login,
Password = context.Password,
};
context.SonarEnd(settings);
}
}
[TaskName("Default")]
[IsDependentOn(typeof(SonarBeginTask))]
[IsDependentOn(typeof(BuildTask))]
[IsDependentOn(typeof(SonarEndTask))]
public class DefaultTask : FrostingTask
{
}
The commad for exect this is:
./build.ps1 --target Default --projectpath C:\route\of\project --sonarkey Prueba --sonarurl http://localhost:9000/ --login admin --password admin --verbosity Diagnostic
But I get this error:
An error occurred when executing task 'SonarBegin'.
Error: System.Exception: No CoreCLR executable found (SonarScanner.MSBuild.dll)
at Cake.Sonar.SonarRunner.Run(SonarSettings settings)
at Cake.Sonar.SonarCakeAliases.SonarBegin(ICakeContext context, SonarBeginSettings settings)
at SonarBeginTask.Run(BuildContext context) in C:\Users\jmedingr\Desktop\MonEES.CICD.Cake\cake\Program.cs:line 166
at Cake.Frosting.FrostingTask`1.Cake.Frosting.IFrostingTask.RunAsync(ICakeContext context)
at Cake.Core.CakeTask.Execute(ICakeContext context)
at Cake.Core.DefaultExecutionStrategy.ExecuteAsync(CakeTask task, ICakeContext context)
at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report)
at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report)
at Cake.Core.CakeEngine.ExecuteTaskAsync(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report)
at Cake.Core.CakeEngine.RunTask(ICakeContext context, IExecutionStrategy strategy, CakeTask task, String target, Stopwatch stopWatch, CakeReport report)
at Cake.Core.CakeEngine.RunTargetAsync(ICakeContext context, IExecutionStrategy strategy, ExecutionSettings settings)
at Cake.Cli.BuildScriptHost`1.RunTargetAsync(String target)
at Cake.Core.Scripting.ScriptHost.RunTarget(String target)
at Cake.Frosting.Internal.FrostingEngine`1.Run(String target)
at Cake.Frosting.Internal.DefaultCommand.Execute(CommandContext context, DefaultCommandSettings settings)
I cant see the way to fix it...
The error you are seeing (No CoreCLR executable found
) is raised by Cake.Sonar, when the required tool is not found.
If you check the ReadMe for Cake.Sonar, it states #tool nuget:?package=MSBuild.SonarQube.Runner.Tool
is needed to run Cake.Sonar.
So I'm guessing your Main
method should look like:
public static int Main(string[] args)
{
return new CakeHost()
.UseContext<BuildContext>()
.InstallTool(new Uri("nuget:?package=MSBuild.SonarQube.Runner.Tool"))
.Run(args);
}
I did not test that, though.