Sonarcloud + bitbucket via gradle plugin

  • ALM used: Bitbucket Cloud
  • CI system used: Bitbucket Cloud
  • Scanner command used when applicable: gradle build sonarqube
  • Languages of the repository: JAVA
  • Error observed: Analyzed by an unknown method
  • Scan detects only master branch of the repo, even if scan was performed on another branch. PR detection doesn’t work → no PR’s in sonarcloud, even if scan has been performed from the branch with opened PR.
gradle config:
    sonarqube {
        properties {
            property "sonar.projectKey", "${project.name}"
            property "sonar.sourceEncoding", "UTF-8"
            property "sonar.organization", System.env.SONAR_ORG
            property "sonar.host.url", System.env.SONAR_URL
        }
    }

Environment:

KUBERNETES_SERVICE_PORT_HTTPS=443
KUBERNETES_SERVICE_PORT=443
BITBUCKET_PROJECT_UUID={47d69714-af38-4e96-8586-73a46331bbc5}
BITBUCKET_BUILD_NUMBER=103
BITBUCKET_REPO_SLUG=MASKED
HOSTNAME=ee9b9cbe-1935-484c-a105-3f6a75019b06-b92f9
LANGUAGE=en_US:en
JAVA_HOME=/opt/java/openjdk
BITBUCKET_DOCKER_HOST_INTERNAL=10.36.98.83
BITBUCKET_STEP_UUID={ee9b9cbe-1935-484c-a105-3f6a75019b06}
GRADLE_HOME=/opt/gradle
AWS_DEFAULT_REGION=MASKED
PIPELINES_JWT_TOKEN=$PIPELINES_JWT_TOKEN
PWD=/opt/atlassian/pipelines/agent/build
BITBUCKET_COMMIT=f299b06de2ae489d08baf77a5b6f8b39a77da893
BITBUCKET_PROJECT_KEY=MED
HOME=/root
LANG=en_US.UTF-8
KUBERNETES_PORT_443_TCP=tcp://10.34.224.1:443
LS_COLORS=
GRADLE_VERSION=7.2
BITBUCKET_GIT_HTTP_ORIGIN=MASKED
BITBUCKET_REPO_UUID=MASKED
SONAR_URL=https://sonarcloud.io
BITBUCKET_REPO_OWNER=MASKED
AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
BITBUCKET_PIPELINE_UUID=MASKED
BITBUCKET_GIT_SSH_ORIGIN=MASKED
BITBUCKET_WORKSPACE=MASKED
BITBUCKET_REPO_FULL_NAME=MASKED
BITBUCKET_STEP_TRIGGERER_UUID={453ae07a-f4d4-421a-a186-1ec5cd615fca}
SONAR_ORG=MASKED
BITBUCKET_REPO_IS_PRIVATE=true
SHLVL=1
AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
BITBUCKET_REPO_OWNER_UUID=MASKED
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_PORT_443_TCP_ADDR=10.34.224.1
CODEARTIFACT_AUTH_TOKEN=MASKED
SONAR_TOKEN=MASKED
DOCKER_HOST=tcp://localhost:2375
BITBUCKET_CLONE_DIR=/opt/atlassian/pipelines/agent/build
KUBERNETES_SERVICE_HOST=10.34.224.1
LC_ALL=en_US.UTF-8
KUBERNETES_PORT=tcp://10.34.224.1:443
KUBERNETES_PORT_443_TCP_PORT=443
PATH=/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
CI=yes
CODEARTIFACT_MAVEN_URL=http://...
BITBUCKET_BRANCH=feature/naming-fix
BITBUCKET_STEP_RUN_NUMBER=1
JAVA_VERSION=jdk-11.0.13+8
_=/usr/bin/printenv

Important note: I don’t have administrator permissions on bitbucket workspace, but sonar plugin installed in bitbucket cloud and project(where I do have full permissions) configured for the specific sonar project:

Hey there.

This is… weird to me. I would expect this value to be true, not yes – and this is a condition in our code to detect anything.

Bitbucket Pipelines Documentation also tells me this should default to true.

Is this being overridden somewhere?

Yes, our code uses this value in our configuration. Can it affect sonar plugin in any kind?

Hey there.

Yes. It must be set to true rather than yes, as this is how SonarCloud determines it’s running in a CI environment and should kick-off autodetection. It’s also the value that Bitbucket states should be used for this environment variable.

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