如果SonarQube失败质量门,则VSTS构建失败

问题描述 投票:2回答:2

我们使用VSTS构建与标准的SonarQube构建步骤:

  • SonarQube for MsBuild - 开始分析
  • ......建造
  • 用于MsBuild的SonarQube - 结束分析

构建后的一段时间我可以在SonarQube中看到分析结果 - 无论是通过还是失败质量门。但即使质量门失败,VSTS构建也是成功的。

如果质量门失败,有没有办法使VSTS构建失败?

接下来:http://docs.sonarqube.org/display/SONAR/Breaking+the+CI+Build我试过寻找report-task.txt文件,但我无法在任何地方看到它。

我可以只运行MSBuild.SonarQube.Runner.exe作为命令行构建步骤,如下所述:http://docs.sonarqube.org/display/SONAR/Analyzing+with+SonarQube+Scanner+for+MSBuild#AnalyzingwithSonarQubeScannerforMSBuild-AnalyzingfromtheCommandLine

但我想我应该首先尝试SonarQube的标准构建步骤

sonarqube azure-devops
2个回答
3
投票

这是一个链接到5.3或更高版本的质量门违规构建失败,它使用SonarQube for MSBuild - 开始分析任务

https://blogs.msdn.microsoft.com/visualstudioalm/2016/02/11/use-sonarqube-quality-gates-to-control-your-visual-studio-team-services-builds/

此更新任务不适用于TFS 2015 Update 1,但可在Update 2 RC1和VSTS(VSO)中使用。

此致,Wes


1
投票

如果声纳质量门失效,我也有这个要求使Build失败。我在sonarqube显示任务后创建了一个power shell任务。以下是查找状态的脚本:

function Get-SonarQubeStatus() {

  # Step 1. Create a username:password pair
  $credPair = "username:password"

  # Step 2. Encode the pair to Base64 string
  $encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credPair))

  # Step 3. Form the header and add the Authorization attribute to it
  $headers = @{ Authorization = "Basic $encodedCredentials" }

  # Step 4. Make the GET request
  $responseData = Invoke-WebRequest -Uri https://localhost/api/qualitygates/project_status?projectKey=<projectkey> -Method Get -Headers $headers -UseBasicParsing

  #write-host $responseData.content

  $x = $responseData.content | ConvertFrom-Json
  $sonarQualityGateResult = $x.projectStatus.status

  if($sonarQualityGateResult -eq "ERROR")
    {
        write-host "CI failed due to Sonarqube quality Gate"
        exit 1
    }

}
© www.soinside.com 2019 - 2024. All rights reserved.