Hi there
Just trying to figure out how to setup SonarQube to only run when building from the Master branch.
I found this from another post:
"We are using Azure DevOps so all I had to do was add a condition so that the Sonar tasks only run on the master branch.
condition: and(succeeded(), eq(variables[‘Build.SourceBranch’], ‘refs/heads/master’))"
I am just not sure were to add this condition? Is it in the “Prepare Analysis” step under “Custom Conditions”? Or someplace else?
I also found this in the SonatQube documentation:
Limiting analysis to relevant branches
You need to add a condition to your pipeline script to ensure only relevant branches are analyzed. For example, you wouldn’t want to run analysis on feature branches that won’t need analysis until they have pull requests .
In the following example, analysis would be limited to branches named master
or release/*
.
if [[ "$CI_BRANCH_NAME" == master ]] || [[ "$CI_BRANCH_NAME" == release/* ]]; then
./gradlew sonarqube
fi
Just not sure were I would add this either - as part of the Prepare Analysis task or as a separate task (as a script)?
Any advice really appreciated.
Thanks