title: Jenkins Integration with Sonar-Scanner
body: <p>I am trying to integrate Jenkins and sonar-scanner to run Angular code. Below are the my setup and configuration.</p>
  
  <p>Source code available path : /home/user/Angular
  SonarQube configured path : /opt/SonarQube
  Sonar-Scanner configured path : /opt/Sonar-Scanner</p>
  
  <pre><code>$ /opt/SonarQube/bin/. /sonar.sh start
  </code></pre>
  
  <p>SonarQube is running, and i can able to access localhost in browser with port number.</p>
  
  <pre><code>http://localhost:9000
  </code></pre>
  
  <p>Next i am running sonar scanner in the terminal using below command </p>
  
  <pre><code>sonar-scanner -X -Dsonar.host.url=http://localhost:9000 -Dsonar.login=admin
  
  INFO: Analysis report uploaded in 552ms
  INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard?id=app
  INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
  INFO: More about the report processing at http://localhost:9000/api/ce/task?id=AW9NPXPGP93qcNh5qcv5
  INFO: Analysis total time: 39.071 s
  INFO: ------------------------------------------------------------------------
  INFO: EXECUTION SUCCESS
  INFO: ------------------------------------------------------------------------
  INFO: Total time: 41.826s
  INFO: Final Memory: 12M/44M
  INFO: ------------------------------------------------------------------------
  </code></pre>
  
  <p>Below are the Jenkins Configuration</p>
  
  <p>1) Manage Jenkins –> Global Tool Configuration –> SonarQube Scanner configured, please find the attached image.<a href="https://i.stack.imgur.com/g3oRi.png" rel="nofollow noreferrer">sonar-scanner Jenkins configuration</a></p>
  
  <p>2) Configure SonarQube server in Jenkins, this will communicate SonarQube Server authentication.</p>
  
  <p>Log in into your SonarQube Server and find following under user bar
  Go to My Account –> Security –> Generate Token</p>
  
  <p><a href="https://i.stack.imgur.com/qN5MV.png" rel="nofollow noreferrer">Sonar-server token jenkins authentication</a></p>
  
  <p>Now the question is, i'm running jenkins pipeline jobs to execute sonar-scanner with below command in pipeline stage </p>
  
  <pre><code>stage('sonar-scanner') {
          container('sonar') {
             // sh "/sonar-scanner/bin/sonar-scanner -X -Dsonar.host.url=http://localhost:9000 -Dsonar.login=admin"
          }
        }
  </code></pre>
  
  <p>Please find the below jenkins Error logs below, its seems unable to reach localhost:9000</p>
  
  <pre><code>+ sonar-scanner -X
  09:25:46.052 INFO: Scanner configuration file: /usr/lib/sonar-scanner/conf/sonar-scanner.properties
  09:25:46.060 INFO: Project root configuration file: NONE
  09:25:46.142 INFO: SonarQube Scanner 4.0.0.1744
  09:25:46.143 INFO: Java 11.0.3 AdoptOpenJDK (64-bit)
  09:25:46.143 INFO: Linux 5.0.0-1027-azure amd64
  
  09:25:46.568 DEBUG: keyStore is : 
  09:25:46.573 DEBUG: keyStore type is : pkcs12
  09:25:46.573 DEBUG: keyStore provider is : 
  09:25:46.573 DEBUG: init keystore
  09:25:46.575 DEBUG: init keymanager of type SunX509
  09:25:46.822 DEBUG: Create: /root/.sonar/cache
  09:25:46.824 INFO: User cache: /root/.sonar/cache
  09:25:46.824 DEBUG: Create: /root/.sonar/cache/_tmp
  09:25:46.827 DEBUG: Extract sonar-scanner-api-batch in temp...
  09:25:46.830 DEBUG: Get bootstrap index...
  09:25:46.831 DEBUG: Download: http://sonarqube:9000/batch/index
  09:25:46.893 ERROR: SonarQube server [http://sonarqube:9000] can not be reached
  09:25:46.893 INFO: ------------------------------------------------------------------------
  09:25:46.894 INFO: EXECUTION FAILURE
  09:25:46.894 INFO: ------------------------------------------------------------------------
  </code></pre>
  
  <p>Could you please some suggest how to fix this, this would be really helpful, due to this issue entire team is affecting.</p>