Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tdshipley
Created March 21, 2018 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdshipley/1dc55fcd96877943465ed5953be02788 to your computer and use it in GitHub Desktop.
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
$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