Unable to add SonarCloud Scan in Bitbucket

Hi,

Currently we are evaluating SonarCloud for Code Analysis and Code Review in our Bitbucket repository (Private) in node.js application. We need your help as we unable to add SonarCloud Scan in Bitbucket. We are getting the following error:

ERROR: Error during SonarScanner execution
java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/EnvironmentInformation has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
	at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:550)
	at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:458)
	at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:452)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:451)
	at org.sonarsource.scanner.api.internal.IsolatedClassloader.loadClass(IsolatedClassloader.java:82)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	at org.sonarsource.scanner.api.internal.batch.DefaultBatchFactory.createBatch(DefaultBatchFactory.java:32)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at com.sun.proxy.$Proxy0.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
	at org.sonarsource.scanner.cli.Main.main(Main.java:61)
ERROR: 
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.

Request your assistance.

Regards,
Amitava
amitava.chattopadhyay@bajajcapital.com

Can you share your Bitbucket Pipelines YML?

Hi Colin,

Bitbucket pipelines YML is attached

image: node:10
pipelines:
  branches:
    dev:
      - step:
          caches:
            - node
          deployment: dev
          script:
            # Clean and install dependencies
            - rm -rf node_modules/
            - rm package-lock.json
            - npm install
            - npm install -g @angular/cli@7.3.8
            # Install Java 17 for SonarCloud
            - apt-get update && apt-get install -y openjdk-17-jdk
            
            
            # Run SonarCloud analysis
            - pipe: sonarsource/sonarcloud-scan:1.4.0
              variables:
                SONAR_TOKEN: $SONAR_TOKEN
                EXTRA_ARGS: >
                  -Dsonar.projectKey=$SONAR_PROJECT_KEY
                  -Dsonar.organization=$SONAR_ORGANIZATION
                  -Dsonar.sources=src
                  -Dsonar.exclusions=**/node_modules/**,**/*.spec.ts
                  -Dsonar.java.jdkHome=/usr/lib/jvm/java-17-openjdk-amd64
            # Verify files and deploy to S3
            - ls -ltr
            - cd dist/BCL-NPS
            - pipe: atlassian/aws-s3-deploy:0.2.4
              variables:
                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
                AWS_DEFAULT_REGION: $AWS_REGION
                ACL: "public-read"
                S3_BUCKET: $AWS_BUCKET_TARGET
                LOCAL_PATH: $(pwd)
            # Invalidate AWS CloudFront cache
            - pipe: docker://rudijs/aws-cloudfront-create-invalidation:1.0.1
              variables:
                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
                DISTRIBUTION_ID: $AWS_DISTRIBUTION_ID

Regards,
Amitava

This is a very old image, that I’m not surprised doesn’t contain Java 17 (the error you’re facing is that only Java 11 is included, which isn’t supported as a SonarScanner runtime).

You should check the logs to see if this installation is even successful. If it is successful, I suggest adding another line to set the JAVA_HOME variable to this installation. For example:

export JAVA_HOME=/usr/lib/jvm/java-17-openjdk

Otherwise, I would suggest you use a newer image with a supported version of Node.

Hi

Now we are using the latest version of node in a new application, but we are getting some error. Please find error & yml file below:

ERROR: Error during SonarScanner execution
java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/EnvironmentInformation has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
  at java.base/java.lang.ClassLoader.defineClass1(Native Method)
  at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
  at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
  at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:550)
  at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:458)
  at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:452)
  at java.base/java.security.AccessController.doPrivileged(Native Method)
  at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:451)
  at org.sonarsource.scanner.api.internal.IsolatedClassloader.loadClass(IsolatedClassloader.java:82)
  at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
  at org.sonarsource.scanner.api.internal.batch.DefaultBatchFactory.createBatch(DefaultBatchFactory.java:32)
  at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.base/java.lang.reflect.Method.invoke(Method.java:566)
  at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
  at com.sun.proxy.$Proxy0.execute(Unknown Source)
  at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
  at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
  at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
  at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
  at org.sonarsource.scanner.cli.Main.main(Main.java:61)
ERROR: 
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
✖ SonarCloud analysis failed. (exit code = 1)

YML File

image: node:18
pipelines:
  branches:
    stage:
      - step:
          caches:
            - node
          deployment: dev
          script:
            - rm -rf node_modules/
            - rm package-lock.json
            - npm install
            - npm install -g @angular/cli@7.3.8
            - apt-get update && apt-get install -y openjdk-17-jdk
            - pipe: sonarsource/sonarcloud-scan:1.4.0
              variables:
                SONAR_TOKEN: $SONAR_TOKEN
                EXTRA_ARGS: >
                  -Dsonar.projectKey=$SONAR_PROJECT_KEY
                  -Dsonar.organization=$SONAR_ORGANIZATION
                  -Dsonar.sources=src
                  -Dsonar.exclusions=**/node_modules/**,**/*.spec.ts
                  -Dsonar.java.jdkHome=/usr/lib/jvm/java-17-openjdk-amd64
            - ng build
            - ls -ltr
            - cd dist/hipr-web
            - pipe: atlassian/aws-s3-deploy:0.2.4
              variables:
                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
                AWS_DEFAULT_REGION:  $AWS_REGION
                ACL: "public-read"
                S3_BUCKET: $STAGE_AWS_BUCKET_TARGET
                LOCAL_PATH: $(pwd)
            - pipe: docker://rudijs/aws-cloudfront-create-invalidation:1.0.1
              variables:
                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
                DISTRIBUTION_ID: $STAGE_AWS_DISTRIBUTION_ID

Regards,

And so there’s part two of my response.

Hi Colin,

We followed as suggested by you, however, still we are getting the error. Is it possible to schedule a google meet session for 10-15 minutes. Sharing the details once again:

ERROR: Error during SonarScanner execution
116
java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/EnvironmentInformation has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0
117
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
118
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
119
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
120
    at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:550)
121
    at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:458)
122
    at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:452)
123
    at java.base/java.security.AccessController.doPrivileged(Native Method)
124
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:451)
125
    at org.sonarsource.scanner.api.internal.IsolatedClassloader.loadClass(IsolatedClassloader.java:82)
126
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
127
    at org.sonarsource.scanner.api.internal.batch.DefaultBatchFactory.createBatch(DefaultBatchFactory.java:32)
128
    at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
129
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
130
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
131
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
132
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
133
    at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
134
    at com.sun.proxy.$Proxy0.execute(Unknown Source)
135
    at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
136
    at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
137
    at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
138
    at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
139
    at org.sonarsource.scanner.cli.Main.main(Main.java:61)
140
ERROR: 
141
ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
image: node:18
pipelines:
  branches:
    stage:
      - step:
          caches:
            - node
          deployment: dev
          script:
            - rm -rf node_modules/
            - rm package-lock.json
            - npm install
            - npm install -g @angular/cli@7.3.8
            - apt-get update && apt-get install -y openjdk-17-jdk
            - export JAVA_HOME=/usr/lib/jvm/java-17-openjdk
            - pipe: sonarsource/sonarcloud-scan:1.4.0
              variables:
                SONAR_TOKEN: $SONAR_TOKEN
                EXTRA_ARGS: >
                  -Dsonar.projectKey=$SONAR_PROJECT_KEY
                  -Dsonar.organization=$SONAR_ORGANIZATION
                  -Dsonar.sources=src
                  -Dsonar.exclusions=**/node_modules/**,**/*.spec.ts
                  -Dsonar.java.jdkHome=/usr/lib/jvm/java-17-openjdk-amd64
            - ng build
            - ls -ltr
            - cd dist/hipr-web
            - pipe: atlassian/aws-s3-deploy:0.2.4
              variables:
                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
                AWS_DEFAULT_REGION:  $AWS_REGION
                ACL: "public-read"
                S3_BUCKET: $STAGE_AWS_BUCKET_TARGET
                LOCAL_PATH: $(pwd)
            - pipe: docker://rudijs/aws-cloudfront-create-invalidation:1.0.1
              variables:
                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
                DISTRIBUTION_ID: $STAGE_AWS_DISTRIBUTION_ID

Regards,

Amitava

Hey there.

Actually, I see the problem now.

This is simply out of date. Try bumping the version.

- pipe: sonarsource/sonarcloud-scan:3.1.0

Then you can remove both these lines.

Hi Colin,

The previous issue seems to be resolved. However, now we are getting another set of error “Container ‘docker’ exceeded” while running pipeline.

`11:05:12.437 INFO  Deploy location /opt/sonar-scanner/.sonar/js/node-runtime, tagetRuntime: /opt/sonar-scanner/.sonar/js/node-runtime/node,  version: /opt/sonar-scanner/.sonar/js/node-runtime/version.txt`

165

`11:05:15.787 INFO  Using embedded Node.js runtime.`

166

`11:05:15.787 INFO  Using Node.js executable: '/opt/sonar-scanner/.sonar/js/node-runtime/node'.`

167

`11:05:17.794 INFO  Memory configuration: OS (18383 MB), Node.js (4144 MB).`

168

`time="2024-12-13T11:06:14Z" level=error msg="error waiting for container: unexpected EOF"`

Regards,

Amitava

Hi Colin,

In addition to the above, sharing the current bitbucket pipeline YML, also for your reference we have tried 2x, 4x & 8x, but the problem remains the same

image: node:18
pipelines:
  branches:
    stage:
      - step:
          caches:
            - node
          deployment: dev
          size: 8x
          script:
            - rm -rf node_modules/
            - rm package-lock.json
            - npm install
            - npm install -g @angular/cli@7.3.8
            - pipe: sonarsource/sonarcloud-scan:3.1.0
              variables:
                SONAR_TOKEN: $SONAR_TOKEN
                EXTRA_ARGS: >
                  -Dsonar.projectKey=$projectKey
                  -Dsonar.organization=$organization
                  -Dsonar.log.level=DEBUG
                  -Dsonar.sources=src
                  -Dsonar.exclusions=**/node_modules/**,**/*.spec.ts
            - ng build
            - ls -ltr
            - cd dist/hipr-web
            - pipe: atlassian/aws-s3-deploy:0.2.4
              variables:
                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
                AWS_DEFAULT_REGION:  $AWS_REGION
                ACL: "public-read"
                S3_BUCKET: $STAGE_AWS_BUCKET_TARGET
                LOCAL_PATH: $(pwd)
            - pipe: docker://rudijs/aws-cloudfront-create-invalidation:1.0.1
              variables:
                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
                DISTRIBUTION_ID: $STAGE_AWS_DISTRIBUTION_ID

Regards,
Amitava

Hi Colin,
Did you have a chance to look into the problem. Request you to suggest the next steps. We are stuck at the moment.

Regards,
Amitava

Since Friday afternoon? No.

Please keep in mind this is a Community forum. You may want to read our FAQ.

I created a topic, when can I expect a response?

This is an open community with people volunteering their free time to provide assistance. We’re eager to contribute to the community, but you are not guaranteed a fast response.

Be patient

  • Wait a few days before bumping a topic that hasn’t received a response.
  • Do not @name mention individuals not involved in the topic.

Contribute as much as you expect to receive

  • Contribute to the community (helping others) as much as you expect to receive help.

It is not a replacement for more structured support

  • If you need SLAs, guaranteed response, privacy, SonarSource also offers Commercial Support.

Hi, Understood and am well aware of this.
Follow-up messages were only meant to seek help from the community and to resolve the issue which we are facing and wanted to move on…
Will look forward to the response.

Regards,
Amitava

I think you’ll want to follow this knowledgebase article from Atlassian:

https://confluence.atlassian.com/bbkb/troubleshooting-bitbucket-pipelines-1141505226.html#TroubleshootingBitbucketPipelines-scenario12

Please note that increasing the Pipeline build step size to 2x, 4x, or 8x (using the size attribute) will not automatically increase the memory allocated to the Docker service container. Docker service with size 2x, 4x, or 8x will still be allocated 1GB of memory by default, unless you configure and allocate more memory explicitly in the YAML file (an example is given below)

Hi Community Team Member(s),

We have checked, tried all the suggested options. However, the issue still persists.
Any help would be appreciated to start to add sonar scan in our bitbucket pipeline, using Sonar Cloud.

Regards,
Amitava

Unfortunately, “We tried everything, now what?” is not really something we can work with in this forum.

  • What exactly did you try?
  • What configuration did you change?
  • How do you know the configuration changes did what they’re supposed to do? What did you see in the logs?
  • Did anything change in the logs / error messages?

Hi Colin,

We have followed this link ( Unable to add SonarCloud Scan in Bitbucket - #14 by Colin ) as you have given us earlier.
We have already shared our pipeline and error in previous chat in the thread. Kindly let me know if anything else need to be shared with you, which can resolve this issue.

Regards,
Amitava

A post was split to a new topic: Issue with SonarQube Bitbucket Pipe