当我尝试使用带有以下开关的SonarQube.Scanner.MSBuild.exe时:
SonarQube.Scanner.MSBuild.exe /k:%CI_COMMIT_REF_NAME% /n:%CI_COMMIT_REF_NAME%
日志转储让我遇到%CI_COMMIT_REF_NAME%的问题。就好像它们不存在或无法找到它们一样。
我也在文件的末尾看到这一行:
'GitLab Commit Issue Publisher' skipped because one of the required properties is missing
这是我的SonarQube.Analysis.xml文件
<SonarQubeAnalysisProperties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.sonarsource.com/msbuild/integration/2015/1">
<!-- The sonarqube server address -->
<Property Name="sonar.host.url">http://server.com:1234</Property>
<Property Name="sonar.sourceEncoding">UTF-8</Property>
<!-- I have no idea if anything below this line works -->
<!-- <Property Name="sonar.projectName">Master</Property> Should be set in job of the gitlab yml
<Property Name="sonar.projectKey">Master</Property> Should be set in job of the gitlab yml -->
<Property Name="sonar.exclusions">folder\**</Property>
<Property Name="sonar.sources">.</Property>
<Property Name="sonar.verbose">true</Property>
<!-- <Property Name="sonar.scanner.dumpToFile">somethingWentWrong.txt</Property> -->
<Property Name="sonar.analysis.mode">issues</Property>
<!--
this is only for forced authentication. the group "everyone" on the server has execute permission so you don't need to fill this out.
<Property Name="sonar.login"></Property>
<Property Name="sonar.password"></Property>
-->
</SonarQubeAnalysisProperties>
这是我用来在gitlab-ci.yml作业中调用SonarQube.Scanner.MSbuild.exe的命令序列:
- SonarQube.Scanner.MSBuild.exe begin /k:doesthiswork /n:doesthiswork
- MSBuild.exe /t:Rebuild directory\Solution.sln
- SonarQube.Scanner.MSBuild.exe end
在Gitlab-ci.yml内部的SonarQube.Scanner.MSBuild.exe调用中使用Gitlab预定义变量我不明白?
gitlab变量:https://docs.gitlab.com/ee/ci/variables/#predefined-variables-environment-variables
答案 0 :(得分:0)
可以使用Gitlab和sonarqube变量;但是它们不能从gitlab-ci.yml中引用。
在gitlab-ci.yml中调用批处理脚本,例如:
- cmd.exe /c callMyBatch.bat
....在callMyBatch.bat内部
SonarQube.Scanner.MSBuild.exe begin /k:%GITLABORENVIRONMENTVAR%
MSBuild.exe /t:Rebuild directory\Solution.sln
SonarQube.Scanner.MSBuild.exe end