如何在 gitlab-ci.yml 中使用带有 SonarQube.Scanner.MSBuild.exe 的 Gitlab 变量

How do I use Gitlab variables with SonarQube.Scanner.MSBuild.exe inside of a gitlab-ci.yml

当我尝试将 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 内部的 SonarQube.Scanner.MSBuild.exe 调用中使用 Gitlab 预定义变量,我有什么不明白的-ci.yml?

gitlab变量:https://docs.gitlab.com/ee/ci/variables/#predefined-variables-environment-variables

可以使用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