我在jenkins管道中执行了任务集成测试和代码覆盖。
使用的工具是 dotcover 和 Nunit 。
当配置为 Integration 时,Nunit在集成测试构建期间通过dotcover执行。
当我在 Visual Studio 中执行配置 Integration 并进行了一些错误测试时,构建失败,一切正常,但是使用< strong> msbuild ,它不会返回任何错误代码,然后jenkins pipelin不会失败。
这种情况使我们处于微妙的状态,因为我们不再相信自己的构建管道。
几天以来我一直在网上寻找解决方案,但我仍然意见一致,这就是为什么我在这里寻求您的帮助。
感谢您的帮助。
slideToggle
node('BUILD_PROJECT') {
stage ('Checkout')
{
checkout scm
}
stage ('Build')
{
bat '"C:/Program Files (x86)/NuGet/nuget.exe" restore -NonInteractive MySolution.sln'
bat "\"C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/MSBuild/15.0/Bin/MSBuild.exe\" /p:Configuration=Release;AssemblyVersion=0.1.0.${env.BUILD_NUMBER} /maxcpucount:8 MySolution.sln"
}
stage ('Integration')
{
bat "\"C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/MSBuild/15.0/Bin/MSBuild.exe\" /p:Configuration=Integration /maxcpucount:8 MySolution.sln"
}
stage ('Publish Coverage')
{
publishHTML target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'Solution/IntegrationProject/bin/Integration/TestResult',
reportFiles: 'ProjectCoverageReport.html',
reportName: 'Project Coverage Report'
]
}
stage ('Setup')
{
bat "\"C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/MSBuild/15.0/Bin/MSBuild.exe\" /p:Configuration=Setup;Platform=x86;AssemblyVersion=0.1.0.${env.BUILD_NUMBER} /maxcpucount:8 MySolution.sln"
}
stage ('Archive')
{
archiveArtifacts artifacts: 'Solution/SetupProject/bin/x86/Setup/MySetup.exe'
}
}
答案 0 :(得分:0)
您应该可以使用dotcover参数 ReturnTargetExitCode 从nunit获取返回代码。
<Target Name="CoverageReport" AfterTargets="CopySqlFiles" Condition="$(Configuration) == Integration">
<Exec Command="..\packages\JetBrains.dotCover.CommandLineTools.2018.1.3\tools\dotCover.exe analyse ^
/TargetExecutable=..\packages\NUnit.ConsoleRunner.3.8.0\tools\nunit3-console.exe ^
/ReturnTargetExitCode ^
/TargetArguments="$(TargetPath)" ^
/Filters=-:nunit.framework;-:IntegrationProjectTest;-:type=MyNamespace.View.*;-:type=*Test ^
/TargetWorkingDir=$(TargetDir) ^
/Output=$(TargetDir)\TestResult\MyCoverageReport.html ^
/ReportType=HTML
/ReturnTargetExitCode">
<Output TaskParameter="ExitCode" PropertyName="DotCoverExitCode" />
</Exec>
<Message Text="Unit Tests Failed!" Condition="$(DotCoverExitCode) != '0'"/>
</Target>