Sonarcloud + Gitlab Could not find ref

Hi everybody.
I have a problem with short branch analysis
I get this warning:

WARN: Could not find ref: "main" in refs/heads, refs/remotes/upstream or refs/remotes/origin

I tried many solutions found on various topics

i have done little debug to see what return :

$ git branch
* mybranch

$ git branch -r

$ ls ./.git/refs/heads/

$ ls ./.git/refs/remotes/origin

$ git fetch origin main
* branch main -> FETCH_HEAD

I set the target branch and other needed things to make sonar-scanner work

$ dotnet sonarscanner begin -k:"${PROJECT_NAME}" -v:"${VERSION}" -d:sonar.login="${SONAR_TOKEN}""${SONAR_HOST_URL}" -o:"${SONAR_ORGANIZATION}""${CI_COMMIT_REF_NAME}""${CI_DEFAULT_BRANCH}" -d:sonar.coverageReportPaths="./Reports_Sonar/SonarQube.xml" -d:sonar.gitlab.commit_sha="${CI_COMMIT_SHA}" -d:sonar.gitlab.ref_name="${CI_COMMIT_REF_NAME}" -d:sonar.gitlab.ref="${CI_COMMIT_REF_NAME}" -d:sonar.gitlab.project_id=${CI_PROJECT_ID} -d:sonar.gitlab.ping_user=true

but i don"t understand why sonar didn’t see my main ref as i see it

ps: i tried to pull, to checkout theses branches too

1 Like

The problem has been resolved by recreating the project on SonarCloud side and using dotnet sonascanner with the minimal configuration.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.