Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
45 lines (34 sloc) 2.26 KB
Write-Host '=============================================================================='
Write-Host 'Task : Validacao de Quality Gate'
Write-Host 'Description : Esta tarefa valida se Quality Gate no SonarQube teve queda, e em caso afirmativo, bloqueia o build.'
Write-Host 'Version : 1.0'
Write-Host 'Author : Michael Costa - michaelbh@gmail.com'
Write-Host 'Help : [More Information](https://localiza.visualstudio.com/wiki/)'
Write-Host '=============================================================================='
if ($Env:SonarToken -eq $null)
{
Write-Host "##vso[task.logissue type=error;]Gentileza configurar a Environment Variable 'SonarToken', com um token de acesso em base64 para acesso a API do SonarQube."
Write-Host "##vso[task.complete result=Failed;]"
return
}
$sonarTaskFile = "$(Agent.BuildDirectory)\.sonarqube\out\.sonar\report-task.txt"
$projectKeyLine = Get-Content -Path $sonarTaskFile | Where-Object { $_ -match 'projectKey=' }
$serverUrl = Get-Content -Path $sonarTaskFile | Where-Object { $_ -match 'serverUrl=' }
$ceTaskUrl = Get-Content -Path $sonarTaskFile | Where-Object { $_ -match 'ceTaskUrl=' }
$dashboardUrl = Get-Content -Path $sonarTaskFile | Where-Object { $_ -match 'dashboardUrl=' }
$projectKey = $projectKeyLine -replace "projectKey=" -replace ""
$ceTaskUrl = $ceTaskUrl -replace "ceTaskUrl=" -replace ""
$dashboardUrl = $dashboardUrl.Split('=')[1]
$serverUrl = $serverUrl.Split('=')[1]
$headersSonar = New-Object 'System.Collections.Generic.Dictionary[[String],[String]]'
$headersSonar.Add('Authorization', $Env:SonarToken)
$response = Invoke-WebRequest -URI $ceTaskUrl -Headers $headersSonar | ConvertFrom-Json
$status = $response.task.status
$analysisUrl = "{0}/api/qualitygates/project_status?analysisId={1}" -f $serverUrl,$response.task.analysisId
$response = Invoke-WebRequest -URI $analysisUrl -Headers $headersSonar | ConvertFrom-Json
if (($response.projectStatus.status -ne 'OK') -and ($response.projectStatus.status -ne 'NONE')) {
$errorMsg = "##vso[task.logissue type=error;] Quality gate nao esta verde. Confira o SonarQube em {0}/dashboard?id={1}" -f $serverUrl,$projectKey
Write-Host $errorMsg
Write-Host "##vso[task.complete result=Failed;]"
}
write-output "Validacao finalizada."
You can’t perform that action at this time.