简体   繁体   English

如果SonarQube无法通过质量门,则VSTS构建失败

[英]Fail VSTS build if SonarQube fails quality gate

We use VSTS build with standard SonarQube build steps: 我们将VSTS构建与标准SonarQube构建步骤结合使用:

  • SonarQube for MsBuild - Begin Analysis SonarQube for MsBuild-开始分析
  • ... build ...建立
  • SonarQube for MsBuild - End Analysis 用于MsBuild的SonarQube-最终分析

Some time after build I can see Analysis results in SonarQube - whether it Passed or Failed quality gate. 构建之后的一段时间,我可以在SonarQube中看到分析结果-无论是通过质量检验还是通过质量检验。 But the VSTS build is successful even if quality gate is Failed. 但是,即使质量门失败,VSTS构建也会成功。

Is there a way to fail a VSTS build if quaility gate is failed? 如果质量门失败,是否有办法使VSTS构建失败?

Following this: http://docs.sonarqube.org/display/SONAR/Breaking+the+CI+Build I've tried looking for report-task.txt file, but I can't see it anywhere. 之后,请执行以下操作: http : //docs.sonarqube.org/display/SONAR/Breaking+the+CI+Build我尝试查找report-task.txt文件,但是在任何地方都看不到它。

I can probably just run MSBuild.SonarQube.Runner.exe as command-line build step, as described here: http://docs.sonarqube.org/display/SONAR/Analyzing+with+SonarQube+Scanner+for+MSBuild#AnalyzingwithSonarQubeScannerforMSBuild-AnalyzingfromtheCommandLine 我可能可以只将MSBuild.SonarQube.Runner.exe作为命令行构建步骤运行,如下所述: http : //docs.sonarqube.org/display/SONAR/Analyzing+with+SonarQube+Scanner+for+MSBuild#AnalyzingwithSonarQubeScannerforMSBuild -AnalyzingfromtheCommandLine

But I thought I should first try standard Build Steps for SonarQube 但是我认为我应该首先尝试SonarQube的标准构建步骤

Here is a link to failing the build on quality gate violations with 5.3 or later, it uses the SonarQube for MSBuild - Begin Analysis task 这是在5.3或更高版本上无法建立基于质量门违规的链接,它使用了SonarQube for MSBuild-Begin Analysis任务

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

This updated task is not available with TFS 2015 Update 1 but is available in Update 2 RC1 and VSTS (VSO). 此更新的任务在TFS 2015 Update 1中不可用,但在Update 2 RC1和VSTS(VSO)中可用。

Regards, Wes 问候,韦斯

I too had this requirement to fail the Build if sonar quality gate fails. 如果声纳质量门失灵,我也有要求无法通过Build。 I did created a power shell task after sonarqube display task. 在声纳显示任务之后,我确实创建了Power Shell任务。 Here is the script to find the status: 这是查找状态的脚本:

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
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM