Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SonarQube jenkins asks for login and password

I am trying to anaylse my maven project through jenkins pipeline.

I have configured my SonarQube server instance in global settings of Jenkins with authorized token and server URL.

Following is the groovy script in my jenkinsfile :

stage('SonarQube analysis') {
            tools {
                   jdk "jdk-8u152"
                }
            steps {
                withSonarQubeEnv('My Sonar') {
                    sh 'mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar -Dsonar.login=XXXXXXXXX'
                }
            }
        }

When I build my project using jenkins I get the following error:

[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar (default-cli) on project MyProject: Not authorized. Please check the properties sonar.login and sonar.password.

I would think this is sufficient to analyse the project. Not really sure what am I missing!

like image 235
saupan Avatar asked Jun 01 '18 15:06

saupan


1 Answers

Okay I am on SonarQube 7.1 and this is how I did it:

  1. Create a new user on SonarQube server. Browse to Administration -> Security -> Users -> Create User. Add login and Name and add a password.

enter image description here

  1. Now login as the newly created user using the username and password. Click on the top right hand corner and click "MY Account" -> Security tab. Enter a token name (for example "Jenkins-Token") and click Generate token. Save this token.

enter image description here

  1. Browse to your SonarQube project -> Administration -> Permissions.
  2. Am assuming your project is private. Search for the above user that you added and add right permissions (Please grant execute analysis permission).

enter image description here

  1. Go to your Jenkins Instance. Click on Manage Jenkins -> Configure System. Scroll down to your SonarQube Server section, either add a new server or edit the existing server to add the token that was generated to the "Server authentication token" field. enter image description here

  2. In the pipeline script call the specific sonarqube server instance that you added in the previous step and pass the right paramters on command line. I didnt pass the authentication token on the command line as it is already configured within the sonarqube server details in enter image description here

like image 140
Isaiah4110 Avatar answered Sep 27 '22 21:09

Isaiah4110