Last active
July 28, 2019 11:19
-
-
Save giacomelli/2ff83d13a8b970aacd4aa94b9182e7bb to your computer and use it in GitHub Desktop.
Publishing a .NET Core project to SonarCloud with Cake - http://diegogiacomelli.com.br/publishing-a-dotnet-core-project-to-sonarcloud-with-cake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#tool nuget:?package=MSBuild.SonarQube.Runner.Tool&version=4.6.0 | |
#addin nuget:?package=Cake.Sonar&version=1.1.22 | |
#addin nuget:?package=Cake.Git&version=0.21.0 | |
var target = Argument("target", "Default"); | |
var solutionDir = "src"; | |
var sonarLogin = "[SONARCLOUD-USER-TOKEN]"; | |
var branch = GitBranchCurrent(".").FriendlyName; | |
Task("Build") | |
.Does(() => | |
{ | |
var settings = new DotNetCoreBuildSettings | |
{ | |
Configuration = "Release", | |
}; | |
DotNetCoreBuild(solutionDir, settings); | |
}); | |
Task("Test") | |
.Does(() => | |
{ | |
var settings = new DotNetCoreTestSettings | |
{ | |
ArgumentCustomization = args => { | |
return args.Append("/p:CollectCoverage=true") | |
.Append("/p:CoverletOutputFormat=opencover"); | |
} | |
}; | |
DotNetCoreTest(solutionDir, settings); | |
}); | |
Task("SonarBegin") | |
.Does(() => | |
{ | |
SonarBegin(new SonarBeginSettings { | |
Key = "[SONARCLOUD-PROJECT-KEY]", | |
Branch = branch, | |
Organization = "[SONARCLOUD-ORGANIZATION]", | |
Url = "https://sonarcloud.io", | |
Exclusions = "**/Samples/**/*.cs,**/*.Tests/*.cs", | |
OpenCoverReportsPath = "**/*.opencover.xml", | |
Login = sonarLogin | |
}); | |
}); | |
Task("SonarEnd") | |
.Does(() => { | |
SonarEnd(new SonarEndSettings{ | |
Login = sonarLogin | |
}); | |
}); | |
Task("Default") | |
.IsDependentOn("SonarBegin") | |
.IsDependentOn("Build") | |
.IsDependentOn("Test") | |
.IsDependentOn("SonarEnd") | |
.Does(()=> { | |
}); | |
RunTarget(target); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#tool nuget:?package=MSBuild.SonarQube.Runner.Tool&version=4.6.0 | |
#addin nuget:?package=Cake.Sonar&version=1.1.22 | |
#addin nuget:?package=Cake.Git&version=0.21.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var target = Argument("target", "Default"); | |
var solutionDir = "src"; | |
var sonarLogin = "[SONARCLOUD-USER-TOKEN]"; | |
var branch = GitBranchCurrent(".").FriendlyName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var branch = EnvironmentVariable("APPVEYOR_REPO_BRANCH") ?? GitBranchCurrent(".").FriendlyName; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Task("Build") | |
.Does(() => | |
{ | |
var settings = new DotNetCoreBuildSettings | |
{ | |
Configuration = "Release", | |
}; | |
DotNetCoreBuild(solutionDir, settings); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Task("Test") | |
.Does(() => | |
{ | |
var settings = new DotNetCoreTestSettings | |
{ | |
ArgumentCustomization = args => { | |
return args.Append("/p:CollectCoverage=true") | |
.Append("/p:CoverletOutputFormat=opencover"); | |
} | |
}; | |
DotNetCoreTest(solutionDir, settings); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Task("SonarBegin") | |
.Does(() => | |
{ | |
SonarBegin(new SonarBeginSettings { | |
Key = "[SONARCLOUD-PROJECT-KEY]", | |
Branch = branch, | |
Organization = "[SONARCLOUD-ORGANIZATION]", | |
Url = "https://sonarcloud.io", | |
Exclusions = "**/Samples/**/*.cs,**/*.Tests/*.cs", | |
OpenCoverReportsPath = "**/*.opencover.xml", | |
Login = sonarLogin | |
}); | |
}); | |
Task("SonarEnd") | |
.Does(() => { | |
SonarEnd(new SonarEndSettings{ | |
Login = sonarLogin | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Task("Default") | |
.IsDependentOn("SonarBegin") | |
.IsDependentOn("Build") | |
.IsDependentOn("Test") | |
.IsDependentOn("SonarEnd") | |
.Does(()=> { | |
}); | |
RunTarget(target); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment