我们使用VSTS构建与标准的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的标准构建步骤
这是一个链接到5.3或更高版本的质量门违规构建失败,它使用SonarQube for MSBuild - 开始分析任务
此更新任务不适用于TFS 2015 Update 1,但可在Update 2 RC1和VSTS(VSO)中使用。
此致,Wes
如果声纳质量门失效,我也有这个要求使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
}
}