-
-
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" |
Yeah, that is a different one.
According to my previous experience, it could be related to memory on server (disk or ram). Have a look on https://community.sonarsource.com/t/analysis-failed-with-unrecoverable-indexation-failures/12329/2
Thanks for answering, but it wasn't for disk space, as pipeline agent is running on Azure free agents and the limit the free-space on disk to 10 GB.
anyway I made it work removing some additional properties that were crashing and by adding this task
- task: Bash@3
displayName: Set Sonar Qube params
inputs:
targetType: 'inline'
script: 'export SONAR_SCANNER_OPTS="-Xmx512m"'
By the way, this is the only way I could pass variables into sonar properties, do it via inline wasn't parsing the properties and assigned literally the string '$(someVar)' instead the var content.
- bash: | # Grab the package version
version=`node -p "const p = require('./package.json'); p.version;"`
echo "##vso[task.setvariable variable=packageVersion]$version"
user="$(git log -1 --pretty=format:%an | perl -pe '$')"
echo "##vso[task.setvariable variable=gitUser]$user"
date_Proy=`date -I`
echo "##vso[task.setvariable variable=dateProy]$date_Proy"
build_ID="$(Build.BuildId)"
echo "##vso[task.setvariable variable=customBuildID]$build_ID"
echo $version $user $date_Proy $build_ID
- bash: | # Insert variables into sonar-project.properties
# echo "sonar.projectDate=$(dateProy)" >> sonar-project.properties
echo "sonar.projectName=mod-seguridad-backend" >> sonar-project.properties
echo "sonar.projectKey=$(SONAR_BACKEND_KEY)" >> sonar-project.properties
echo "sonar.projectVersion=$(packageVersion)-$(Build.SourceBranchName)-$(gitUser)-$(customBuildID)" >> sonar-project.properties
echo "sonar.analysis.revision=$(Rev:.r)" >> sonar-project.properties
echo "sonar.analysis.branch=$(Build.SourceBranchName)" >> sonar-project.properties
echo "sonar.analysis.buildid=$(Build.BuildId)" >> sonar-project.properties
- task: SonarQubePrepare@4
displayName: Sonar Qube Prepare
inputs:
SonarQube: 'sonar-ragasa-dev'
scannerMode: 'CLI'
configMode: 'file'
configFile: 'sonar-project.properties'
Huh, interesting.
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".
@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
how to use this or similar in
vmImage: 'ubuntu-latest'
?EDIT:
Tried it myself, looks like it works same, it solved the error but it crashed with a different one on Publish task: