dotnet.exe锁定SonarScanner.MSBuild.Common.dll

Nau*_*zet 4 sonarqube sonarqube-scan

晚上好,

我在Jenkins的2.1项目中使用.Net Core 2.0版本https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+MSBuild:

withSonarQubeEnv('SonarQubeMain') {
    bat "dotnet ${globals.SONAR_QUBE_MSBUILD_PATH}\\SonarScanner.MSBuild.dll begin /k:\"${globals.SONAR_QUBE_PROJECT}\" /d:sonar.host.url=${globals.SONAR_HOST_URL} /d:sonar.cs.xunit.reportsPaths=\"XUnit.xml\" /d:sonar.cs.opencover.reportsPaths=\"coverage.xml\"
}

bat "dotnet build --version-suffix ${env.BUILD_NUMBER}"

dir('test/mytestprojecthere') {
    bat 'D:\\OpenCover\\OpenCover.Console.exe -target:"c:\\Program Files\\dotnet\\dotnet.exe" -targetargs:"xunit --no-build -xml XUnit.xml" -output:coverage.xml -oldStyle -filter:"-[*Tests*]*" -register:user'
}
withSonarQubeEnv('SonarQubeMain') {
    bat "dotnet ${globals.SONAR_QUBE_MSBUILD_PATH}\\SonarScanner.MSBuild.dll end"
}
Run Code Online (Sandbox Code Playgroud)

它适用于第一个构建,但在下一个构建中,它失败了:

Failed to create an empty directory 'D:\Jenkins\workspace\xxxxxxxx\.sonarqube'. 
Please check that there are no open or read-only files in the directory and that you have the necessary read/write permissions.

Detailed error message: Access to the path 'SonarScanner.MSBuild.Common.dll' is denied.
Run Code Online (Sandbox Code Playgroud)

并检查我的Windows服务器,我可以看到多个.Net核心主机后台进程.如果我杀了这些我可以再建造..

我为msBuild推荐/nodereuse:false了MSBuild,但似乎不适用于dotnet核心版本?

fst*_*eff 9

我们刚刚遇到这个问题,发现它与 dotnet 和 msbuild 对先前多线程构建留下的节点的重用有关。

要避免此问题,请在命令行上使用 或/nodereuse:false/nr:false如下所示:

msbuild /m /nr:false myproject.proj

msbuild /m /nodereuse:false myproject.proj

dotnet restore myproject.sln /nodereuse:false
Run Code Online (Sandbox Code Playgroud)


dun*_*anp 5

仅供参考@Nauzet在Scanner for MSBuild回购中打开了一个问题:#535.

总结一下:

  • 开始和结束步骤似乎运行良好,并且dotnet.exe按预期为这些进程关闭
  • 在构建复杂的解决方案时,会启动多个dotnet.exe实例,并且在构建完成时不会立即关闭.在更简单的解决方案上似乎没有出现这个问题.
  • 如果使用dotnet builddotnet msbuild触发构建阶段,则会出现此问题
  • 变通方法:直接使用msbuild构建,或使用dotnet build/nodereuse:false构建

仅供参考,扫描仪MSBuild有几个在构建阶段调用的自定义任务.这些使用被锁定的程序集.自定义任务没有什么不寻常之处; 他们只是从磁盘上的文件中读取数据.在这一点上,我不相信它是扫描仪MSBuild的一个问题.


Isa*_*110 0

请如下所示编辑您的管道脚本,它应该可以正常工作:

    withSonarQubeEnv('SonarQubeMain') {
    bat "dotnet ${globals.SONAR_QUBE_MSBUILD_PATH}\\SonarScanner.MSBuild.dll begin /k:\"${globals.SONAR_QUBE_PROJECT}\" /d:sonar.host.url=${globals.SONAR_HOST_URL} /d:sonar.cs.xunit.reportsPaths=\"XUnit.xml\" /d:sonar.cs.opencover.reportsPaths=\"coverage.xml\"

bat "dotnet build --version-suffix ${env.BUILD_NUMBER}"

dir('test/mytestprojecthere') {
    bat 'D:\\OpenCover\\OpenCover.Console.exe -target:"c:\\Program Files\\dotnet\\dotnet.exe" -targetargs:"xunit --no-build -xml XUnit.xml" -output:coverage.xml -oldStyle -filter:"-[*Tests*]*" -register:user'
}

bat "dotnet ${globals.SONAR_QUBE_MSBUILD_PATH}\\SonarScanner.MSBuild.dll end"
    }
Run Code Online (Sandbox Code Playgroud)

更新

这是我使用的 dotnet core 应用程序管道构建脚本,它运行良好,没有任何问题:

bat "dotnet ${sqScannerMsBuildHome}\\SonarScanner.MSBuild.dll begin /k:yoursonarprojectkey /n:yoursonarprojectname /v:1.0 /d:sonar.host.url=%SONAR_HOST_URL%"
bat 'dotnet build'
bat "dotnet ${sqScannerMsBuildHome}\\SonarScanner.MSBuild.dll end"
Run Code Online (Sandbox Code Playgroud)