-
-
Save wilbit/4eba5b9bbf9dced260fdde7e8242964c to your computer and use it in GitHub Desktop.
- powershell: | | |
$params = "$env:SONARQUBE_SCANNER_PARAMS" -replace '"sonar.branch.name":"[\w/,-.]*"\,?' | |
Write-Host "##vso[task.setvariable variable=SONARQUBE_SCANNER_PARAMS]$params" |
@poychang, it does not provide the ability to analyse different branches of the same Git repository using, for instance, different SonarQube projects (I don't believe it is a good idea to change a default branch each time, it event won't work for running several builds on different branches simultaneously).
The gist does (at least it did when I used it).
You are right. This gist is more generic use and it’s work!
For my scenario, I only scan code on DEV branch. We only commit new code to DEV and after that we use PR. No new code, no need to scan. So, I choose change default branch to reach that goal.
👍
If anyone is looking for a non-windows variant, this works fine on ubuntu images:
- script: |
FILTERED_PARAMS=$(echo $SONARQUBE_SCANNER_PARAMS | sed 's/"sonar.branch.name":"[^"]*"\,//g')
echo "##vso[task.setvariable variable=SONARQUBE_SCANNER_PARAMS]$FILTERED_PARAMS"
displayName: Filter out non-CE sonar parameters
If anyone is looking for a non-windows variant, this works fine on ubuntu images:
I use powershell
on Linux machines (Azure Pipelines Microsoft-managed agents) and it works well.
- script: | FILTERED_PARAMS=$(echo $SONARQUBE_SCANNER_PARAMS | sed 's/"sonar.branch.name":"[^"]*"\,//g') echo "##vso[task.setvariable variable=SONARQUBE_SCANNER_PARAMS]$FILTERED_PARAMS" displayName: Filter out non-CE sonar parameters
@dasMulli , for your script I would use bash
instead of script
because script
on Windows machines uses cmd.exe
and the commands from your script won't work via cmd.exe
, so, there is not reason to use a generic script
task.
Hello, @wilbit,
How can I use this with Mac agent?
I tried and the error was:
/Users/runner/work/_temp/ebba7608-9021-4e4f-9953-4dd7bc559b34.sh: line 1: =: command not found
/Users/runner/work/_temp/ebba7608-9021-4e4f-9953-4dd7bc559b34.sh: line 2: Write-Host: command not found
@ElaineBSchwaner , for Mac agent you better use @dasMulli 's version for Bash shell
The final version looks like this
- bash: |
FILTERED_PARAMS=$(echo $SONARQUBE_SCANNER_PARAMS | sed 's/"sonar.branch.name":"[\w/,-.]*"\,//g')
echo "##vso[task.setvariable variable=SONARQUBE_SCANNER_PARAMS]$FILTERED_PARAMS"
displayName: Filter out non-CE sonar parameters
By default, SonarQube CE only support analysis "master" branch. But you can set default branch on Azure DevOps to "develop" or any other branch. That make SonarQube treat the branch like "master".