# Unable to connect to SonarCloud

**URL:** <https://community.jenkins.io/t/unable-to-connect-to-sonarcloud/19902>\
**Category:** Using Jenkins\
**Tags:** question\
**Created:** [September 20, 2024, 5:20pm UTC](https://community.jenkins.io/t/unable-to-connect-to-sonarcloud/19902 "2024-09-20T17:20:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![IliyanKostov9](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/iliyankostov9/32/10304_2.png) [@IliyanKostov9](https://community.jenkins.io/u/IliyanKostov9)\
**Post date:** [September 20, 2024, 5:20pm UTC](https://community.jenkins.io/t/unable-to-connect-to-sonarcloud/19902/1 "2024-09-20T17:20:39Z")

</div>

Hello,

I’m having problems with performing SonarQube analysis on Jenkins and I can’t figure out how to fix it.  
When the workflow reaches the `SonarQube analysis` step, it just hangs indefinitely until it hits the timeout.

**Setup:**  
I’m hosting my Jenkins server on an EC2 t2 micro instance, the cloud agents are setup as 2 Lambda functions.

**Additional notes:**

- I’m not using a reverse proxy
- security groups of the instance allow HTTPS and HTTP traffic
- the agents run Java11 and are able to perform any non-sonarqube type of jobs
- I have enabled `Inbound TCP Agent Protocol/4 (TLS encryption`
- I have enabled `50000 TCP port for inbound agents` (required for the Lambda connections)

**Observations** :

- when I attempt to ping the SonarCloud domain from the agent, I don’t receive any response (possible network issue?)
- Jenkins system logs are not showing any errors

**Console log:**

```auto
process apparently never started in /tmp/workspace/multi_feat_django-app-controller@tmp/durable-013b3b48
(running Jenkins temporarily with -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.LAUNCH_DIAGNOSTICS=true might make the problem clearer)
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Quality Gate)
Stage "Quality Gate" skipped due to earlier failure(s)
[Pipeline] getContext
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code -2

GitHub has been notified of this commit’s build result

Finished: FAILURE

```

**Jenkins declaration:**

```auto
pipeline {
  agent any
        options {
          disableConcurrentBuilds()
        }
        stages {
          stage('Git checkout') {
          agent { label 'lambda-java'}
            steps {
              git branch: env.BRANCH_NAME , url: 'https://github.com/IliyanKostov9/portfolio.git'
            }
        }
          stage("SonarQube analysis") {
          agent { label 'lambda-java'}
            environment {
              scannerHome = tool 'SonarTool';
            }
            steps {
              script {
                withSonarQubeEnv(installationName: 'SonarCloud', credentialsId: '8049a509-1e79-4369-8240-2f413248d607') {
                  sh "${scannerHome}/bin/sonar-scanner"
                  }
              }
            }
          }
          stage("Quality Gate") {
            agent { label 'lambda-java'}
            steps {
              timeout(time: 1, unit: 'HOURS') {
               waitForQualityGate abortPipeline: true, credentialsId: 'Sonar-token'
              }
            }
          }
        }
      }

```

Any help would be much appreciated!

---

<div class="post-metadata">

**Author:** ![sodul](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/sodul/32/7828_2.png) [@sodul](https://community.jenkins.io/u/sodul)\
**Post date:** [September 20, 2024, 7:17pm UTC](https://community.jenkins.io/t/unable-to-connect-to-sonarcloud/19902/2 "2024-09-20T19:17:49Z")

</div>

We gave up in the Sonar plugin as it was not working as intended, including crashing the pipelines IIRC. Instead we just embed Sonar Scanner into our CI container and call it as a regular process.

This has worked well for us for the past 5 years. The ‘downside’ is that we need to pass the sonar token explicitly to the step, but we are going to address that by writing a custom step that will get the creds and call the scanner in one line.

Note that for SonarCloud the Scanner does require JRE 17, even if you are scanning for java 11 code:

> **[Scanner environment & SonarCloud](https://docs.sonarsource.com/sonarcloud/appendices/scanner-environment/)**
>
> Information about setting up your Sonar scanner environment in your CI to run analyses. Details include requirements and CI-specific environment variables.

The scanner can be downloaded, with a compatible JRE here:

> **[SonarScanner CLI](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner/)**
>
> The SonarScanner CLI is the scanner to use when there is no specific scanner for your build system.

To test the network connectivity between your EC2 instance and Sonarcloud I would not use ping as ping is disabled on a lot of servers nowadays.

Try this:

```shell
curl https://sonarcloud.io/api/webservices/list

```

This should dump a big json document defining the SonarCloud API. If you can retrieve it with `curl` or `wget` then you know your EC2 instance is capable of communicating with the SonarCloud API.

---

<div class="post-metadata">

**Author:** ![IliyanKostov9](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/iliyankostov9/32/10304_2.png) [@IliyanKostov9](https://community.jenkins.io/u/IliyanKostov9)\
**Post date:** [September 25, 2024, 3:54pm UTC](https://community.jenkins.io/t/unable-to-connect-to-sonarcloud/19902/3 "2024-09-25T15:54:02Z")

</div>

Hello,

thanks for your detailed response!

> [@sodul](#):
>
> We gave up in the Sonar plugin as it was not working as intended, including crashing the pipelines IIRC. Instead we just embed Sonar Scanner into our CI container and call it as a regular process.

But isn’t the global tool for sonarqube essentially the sonar-scanner ?  
Theoretically it shouldn’t behave much differently than the container one, only if there are some missing dependencies on the agent side, that the sonar-scanner requires it - but still I think it should throw an appropriate error if that was the case.

> [@sodul](#):
>
> Note that for SonarCloud the Scanner does require JRE 17, even if you are scanning for java 11 code:

Yep I can confirm on that, running sonar scanner on jdk11 will then try to find jdk17.  
Funny thing is that the furthest I’ve went with this issue is with version 11 (e.g it is actually recognizing that there is java installed), but with 17 or higher it’s stuck.

> [@sodul](#):
>
> The scanner can be downloaded, with a compatible JRE here:

I have also tried by installing it via the global tool configuration (non-maven), but no luck :(.

> [@sodul](#):
>
> [SonarScanner CLI](https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner/)
> 
> To test the network connectivity between your EC2 instance and Sonarcloud I would not use ping as ping is disabled on a lot of servers nowadays.

Yes, that’s right, that was a noobie mistake from my part. I’m always forgetting to enable ICMP for this purpose…

> [@sodul](#):
>
> This should dump a big json document defining the SonarCloud API. If you can retrieve it with `curl` or `wget` then you know your EC2 instance is capable of communicating with the SonarCloud API.

I tried that and I don’t think the agents (Lambdas) were able to do so, probably because of not enabling HTTPS for `Inbound TCP Agent Protocol/port`.

Anyhow I decided that my t2 instance was too under-powered for performing daily CI tasks, so I have removed it.

Thanks @sodul for the help!
