Created
March 21, 2018 13:22
-
-
Save tdshipley/1dc55fcd96877943465ed5953be02788 to your computer and use it in GitHub Desktop.
Script for starting SonarQube differently for PR or Master Branch in CI using PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$github_branch_refs_parts = "%teamcity.build.branch%" -split "/" | |
$is_pr = ($github_branch_refs_parts.Count -eq 2 -and $github_branch_refs_parts[1] -eq "merge") | |
if (-Not $is_pr) { | |
Write-Host "Running SonarQube in master branch mode" | |
SonarQube.Scanner.MSBuild.exe begin /k:"%sonar.project%" /d:"sonar.host.url=%sonar.host.url%" /d:sonar.cs.dotcover.reportsPaths="dotCover.html" /v:"%build.number%" | |
} else { | |
Write-Host "Running SonarQube in PR Mode" | |
$pull_request_number = $github_branch_refs_parts[0] | |
$repo = "%repo_owner%" + "/" + "%name%" | |
$command = 'SonarQube.Scanner.MSBuild.exe' + | |
' begin' + | |
' /k:' + '%sonar_project%' + | |
' /v:' + "%build_number%" + | |
' /d:sonar.host.url=' + "%sonar_hosturl%" + | |
' /d:sonar.github.pullRequest=' + $pull_request_number + | |
' /d:sonar.github.repository=' + $repo + | |
' /d:sonar.github.oauth=' + "%sonarqube_github_oauth_token%" + | |
' /d:sonar.analysis.mode=' + "preview" + | |
' /d:sonar.scanAllFiles=' + "true" + | |
' /d:sonar.github.endpoint=' + "%github_api_endpoint%" | |
Write-Host $command | |
Invoke-Expression $command | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment