我正在使用TeamCity和Cake建立一个新的构建服务器来构建一个c#类库和测试项目。
我试图将SonarQube添加到Cake构建脚本中。 Cake已存在一个插件(https://github.com/AgileArchitect/Cake.Sonar),我在TeamCity BuildAgent的工作文件夹中手动运行cake build脚本时工作得很好,但是当它作为TeamCity运行时构建步骤MSBuild和SonarQube之间的集成似乎已经破裂。
通过TC运行时,我在构建日志中遇到的错误是:
The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects. Possible causes: 1. The project has not been built - the project must be built in between the begin and end steps 2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 12.0 upwards are supported 3. The begin, build or end steps have not all been launched from the same folder
这些都不适用于我。 cake脚本在两种情况下都运行begin,build和end步骤。我已经注销了当前目录,并且两种情况都符合预期,并且MSBuild版本完全相同。
在日志中,SonarBegin任务以相同的方式记录命令行和TC。这两个日志中唯一的重要区别在于构建步骤:
在我看来,就像集成应该由MSBuild从Sonar中获取一些设置一样,比如设置RunCodeAnalysis目标并在csc.exe调用中添加/ ruleset等参数,从TC运行时就不会发生这种情况。
任何人都有任何关于如何解决问题的建议?
(工作 - 从TeamCity代理工作目录中的powershell命令行运行)
ValidateSolutionConfiguration: Building solution configuration "Release|Any CPU". The target "RunCodeAnalysis" listed in a BeforeTargets attribute at "C:\TeamCity\buildAgent\work\fd1026da6d1bbdb9\.sonarqube\bin\targets\SonarQube.Integration.targets (340,11)" does not exist in the project, and will be ignored. The target "RunCodeAnalysis" listed in an AfterTargets attribute at "C:\TeamCity\buildAgent\work\fd1026da6d1bbdb9\.sonarqube\bin\targets\SonarQube.Integration.targets (391,11)" does not exist in the project, and will be ignored. Project "C:\TeamCity\buildAgent\work\fd1026da6d1bbdb9\ContractManagement.Common.sln" (1) is building "C:\TeamCity\buildAgent\work\fd1026da6d1bbdb9\src\ContractManagement.Common\ContractManagement.Common.csproj" (2) on node 1 (default targets). GenerateTargetFrameworkMonikerAttribute: Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files. CreateProjectSpecificDirs: Directory "C:\TeamCity\buildAgent\work\fd1026da6d1bbdb9\.sonarqube\out\\ContractManagement.Common_AnyCPU_Release_5799" doesn't exist. Skipping. Creating directory "C:\TeamCity\buildAgent\work\fd1026da6d1bbdb9\.sonarqube\out\\ContractManagement.Common_AnyCPU_Release_5799". Directory "C:\TeamCity\buildAgent\work\fd1026da6d1bbdb9\.sonarqube\conf\\ContractManagement.Common_AnyCPU_Release_5799" doesn't exist. Skipping. Creating directory "C:\TeamCity\buildAgent\work\fd1026da6d1bbdb9\.sonarqube\conf\\ContractManagement.Common_AnyCPU_Release_5799". CoreCompile: C:\Program Files (x86)\MSBuild\14.0\bin\amd64\csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:TRACE /highentropyva+ /reference:C:\TeamCity\buildAgent\work\fd1026da6d1bbdb9\packages\Dapper.1.50.2\lib\net451\Dapper.dll /reference:C:\TeamCity\buildAgent\work\fd1026da6d1bbdb9\packages\Microsoft.ApplicationInsights.2.2.0\lib\net45\Microsoft.ApplicationInsights.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\Microsoft.CSharp.dll" /reference:C:\TeamCity\buildAgent\work\fd1026da6d1bbdb9\packages\morelinq.2.1.0\lib\net35\MoreLinq.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\mscorlib.dll" /reference:C:\TeamCity\buildAgent\work\fd1026da6d1bbdb9\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Configuration.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Data.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Xml.dll" /debug:pdbonly /filealign:512 /optimize+ /out:obj\Release\UdGroup.ContractManagement.Common.dll /ruleset:C:\TeamCity\buildAgent\work\fd1026da6d1bbdb9\.sonarqube\conf\SonarQubeRoslyn-cs.ruleset /errorlog:C:\TeamCity\buildAgent\work\fd1026da6d1bbdb9\src\ContractManagement.Common\bin\Release\UdGroup.ContractManagement.Common.dll.RoslynCA.json /subsystemversion:6.00 /target:library /warnaserror- /utf8output /analyzer:C:\Users\michael.tong\AppData\Local\Temp\.sonarqube\.static\csharp_1.22.0.1631\SonarAnalyzer-1.22.0.1631.zip\Google.Protobuf.dll /analyzer:C:\Users\michael.tong\AppData\Local\Temp\.sonarqube\.static\csharp_1.22.0.1631\SonarAnalyzer-1.22.0.1631.zip\SonarAnalyzer.CSharp.dll /analyzer:C:\Users\michael.tong\AppData\Local\Temp\.sonarqube\.static\csharp_1.22.0.1631\SonarAnalyzer-1.22.0.1631.zip\SonarAnalyzer.dll /additionalfile:C:\TeamCity\buildAgent\work\fd1026da6d1bbdb9\.sonarqube\conf\cs\SonarLint.xml /additionalfile:C:\TeamCity\buildAgent\work\fd1026da6d1bbdb9\.sonarqube\conf\\ContractManagement.Common_AnyCPU_Release_5799\ProjectOutFolderPath.txt Authentication\AuthDetails.cs Authentication\Authenticator.cs Authentication\AuthResult.cs Authentication\IAuthenticator.cs Dto\BaseRuleSet.cs Dto\CompanyCheckResult.cs Dto\CompanyTypeEnum.cs Dto\Contract.cs Dto\ContractHeader.cs Dto\ContractSubmission.cs Dto\CreditCheckData.cs Dto\CreditCheckDecisionEnum.cs Dto\CreditCheckResult.cs Dto\CreditDecision.cs Dto\DbDataValue.cs Dto\DatabaseLocation.cs Dto\DbMetaData.cs Dto\DbMetaDataDictionary.cs Repositories\BaseContractRepository.cs Managers\ContractManager.cs Dto\ContractStatus.cs Dto\DbDataValueDictionary.cs Dto\FieldValueDictionary.cs Managers\ContractStatusManager.cs Managers\IContractStatusManager.cs Managers\ICreditVetRuleSet.cs Util\AppInsights.cs Util\Constants.cs Util\ContractSubmissionGenerator.cs Repositories\IContractRepository.cs Dto\IFieldWithDependencySupport.cs Dto\ISiteFieldValidator.cs Dto\PopulatedField.cs Dto\FieldMetaData.cs Dto\StatusResponse.cs Dto\ValidatedSiteField.cs Dto\ValidationFailureType.cs Dto\ValidationRequest.cs Dto\ValidationResponse.cs Properties\AssemblyInfo.cs Util\IContractSubmissionGenerator.cs Repositories\IEntityDataRepository.cs Repositories\IFieldMetaDataRepository.cs Repositories\QuickQuoteRepository.cs Repositories\RegistrationRepository.cs Repositories\ContractDataRepository.cs Repositories\FieldMetaDataRepository.cs Dto\EntityType.cs Util\AppConfigReader.cs Util\EnumHelper.cs Util\Extensions.cs Repositories\IEntityRepository.cs Util\FieldDependencyHelper.cs Util\IUDLogger.cs Util\SiteDetailsConfigDecorator.cs Util\IConfigReader.cs Util\TypeHelper.cs "C:\Users\michael.tong\AppData\Local\Temp\.NETFramework,Version=v4.5.2.AssemblyAttributes.cs" ... Warnings here
(不工作 - 由TeamCity运营)
ValidateSolutionConfiguration: Building solution configuration "Release|Any CPU". Project "C:\TeamCity\buildAgent\work\fd1026da6d1bbdb9\ContractManagement.Common.sln" (1) is building "C:\TeamCity\buildAgent\work\fd1026da6d1bbdb9\src\ContractManagement.Common\ContractManagement.Common.csproj" (2) on node 1 (default targets). CoreCompile: C:\Program Files (x86)\MSBuild\14.0\bin\amd64\csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:TRACE /highentropyva+ /reference:C:\TeamCity\buildAgent\work\fd1026da6d1bbdb9\packages\Dapper.1.50.2\lib\net451\Dapper.dll /reference:C:\TeamCity\buildAgent\work\fd1026da6d1bbdb9\packages\Microsoft.ApplicationInsights.2.2.0\lib\net45\Microsoft.ApplicationInsights.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\Microsoft.CSharp.dll" /reference:C:\TeamCity\buildAgent\work\fd1026da6d1bbdb9\packages\morelinq.2.1.0\lib\net35\MoreLinq.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\mscorlib.dll" /reference:C:\TeamCity\buildAgent\work\fd1026da6d1bbdb9\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Configuration.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Data.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Xml.dll" /debug:pdbonly /filealign:512 /optimize+ /out:obj\Release\UdGroup.ContractManagement.Common.dll /subsystemversion:6.00 /target:library /utf8output Authentication\AuthDetails.cs Authentication\Authenticator.cs Authentication\AuthResult.cs Authentication\IAuthenticator.cs Dto\BaseRuleSet.cs Dto\CompanyCheckResult.cs Dto\CompanyTypeEnum.cs Dto\Contract.cs Dto\ContractHeader.cs Dto\ContractSubmission.cs Dto\CreditCheckData.cs Dto\CreditCheckDecisionEnum.cs Dto\CreditCheckResult.cs Dto\CreditDecision.cs Dto\DbDataValue.cs Dto\DatabaseLocation.cs Dto\DbMetaData.cs Dto\DbMetaDataDictionary.cs Repositories\BaseContractRepository.cs Managers\ContractManager.cs Dto\ContractStatus.cs Dto\DbDataValueDictionary.cs Dto\FieldValueDictionary.cs Managers\ContractStatusManager.cs Managers\IContractStatusManager.cs Managers\ICreditVetRuleSet.cs Util\AppInsights.cs Util\Constants.cs Util\ContractSubmissionGenerator.cs Repositories\IContractRepository.cs Dto\IFieldWithDependencySupport.cs Dto\ISiteFieldValidator.cs Dto\PopulatedField.cs Dto\FieldMetaData.cs Dto\StatusResponse.cs Dto\ValidatedSiteField.cs Dto\ValidationFailureType.cs Dto\ValidationRequest.cs Dto\ValidationResponse.cs Properties\AssemblyInfo.cs Util\IContractSubmissionGenerator.cs Repositories\IEntityDataRepository.cs Repositories\IFieldMetaDataRepository.cs Repositories\QuickQuoteRepository.cs Repositories\RegistrationRepository.cs Repositories\ContractDataRepository.cs Repositories\FieldMetaDataRepository.cs Dto\EntityType.cs Util\AppConfigReader.cs Util\EnumHelper.cs Util\Extensions.cs Repositories\IEntityRepository.cs Util\FieldDependencyHelper.cs Util\IUDLogger.cs Util\SiteDetailsConfigDecorator.cs Util\IConfigReader.cs Util\TypeHelper.cs "C:\TeamCity\buildAgent\temp\buildTmp\.NETFramework,Version=v4.5.2.AssemblyAttributes.cs"
答案 0 :(得分:2)
经过几天的侦探工作,我已经找到了解决问题的方法。根本原因是当MSBuild运行时,需要与MSBuild集成的声纳目标未被拾取。
原因是TeamCity构建代理作为本地系统帐户运行,这意味着它用于存储目标文件的MSBuild目录是:
C:\Windows\system32\config\systemprofile\AppData\Local\Microsoft\MSBuild
但是,SonarQube.Scanner.MSBuild.exe是针对32位编译的,因此在64位操作系统仿真期间此路径会发生变化:
C:\Windows\sysWOW4\config\systemprofile\AppData\Local\Microsoft\MSBuild
但是,当MSBuild步骤运行时, 64位,所以它在system32文件夹中查找!
您可以尝试更改构建代理程序在其下运行的用户,但这不起作用。这是我相信TeamCity Build代理如何工作的一个怪癖。基本上,环境设置中的appData
文件夹无法正确调整。
我开始工作的方法是下载sonarqube扫描仪的源代码并编译64位版本。
其他可能有用的选项,我现在要研究一下: