Skip to content

Instantly share code, notes, and snippets.

@wilbit
Last active May 30, 2023 20:58
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save wilbit/4eba5b9bbf9dced260fdde7e8242964c to your computer and use it in GitHub Desktop.
Save wilbit/4eba5b9bbf9dced260fdde7e8242964c to your computer and use it in GitHub Desktop.
It removes sonar.branch.name property in Azure Pipeline. Put it somewhere between your SonarQubePrepare and SonarQubeAnalyze tasks.
- powershell: |
$params = "$env:SONARQUBE_SCANNER_PARAMS" -replace '"sonar.branch.name":"[\w/,-.]*"\,?'
Write-Host "##vso[task.setvariable variable=SONARQUBE_SCANNER_PARAMS]$params"
@dasMulli
Copy link

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

@wilbit
Copy link
Author

wilbit commented Nov 12, 2021

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.

@ElaineBSchwaner
Copy link

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

@wilbit
Copy link
Author

wilbit commented Jan 22, 2023

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment