We’re having issues getting code coverage on PRs. The coverage is never showing on PRs but works on the master branch. Also, there’s that message the branch or pullRequest parameter is missing showing up even if those properties are set.
You need to pass additional parameters when using the CLI. This is part of the script we use to wrap our calls to the sonar scanner:
if [[ $CHANGE_ID ]]; then
# For PRs the head of the branch before the local merge is what we are looking for.
git log HEAD@{1} -1 -q | head -1 | cut -f 2 -d' '
sonar_args=(
"-Dsonar.pullrequest.key=$CHANGE_ID"
"-Dsonar.pullrequest.base=$CHANGE_TARGET"
"-Dsonar.pullrequest.branch=$CHANGE_BRANCH"
"-Dsonar.scm.revision=$(git log HEAD@{1} -1 -q | head -1 | cut -f 2 -d' ')"
)
else
branch="$(echo $GIT_BRANCH | sed -e 's|^origin/||')"
sonar_args=("-Dsonar.branch.name=$branch")
fi
sonar-scanner "${sonar_args[@]}"