SonarQube Test Failing Consistently

42 views Asked by At

I have tried to build a webapp application, test using sonarqube, deploy to nexus as artifactory, build docker image and push to a docker repository and finally deploy to tomcat. However, my script doesn't run past Sonarqube before pulling up this error. I would appreciate insight into resolving this problem.

Please find below my script and the corresponding error log.

  pipeline {
    agent any
    tools{
        maven "maven 3.9.4"
    }
    stages {
        stage("Initialization"){
            steps{
                sh '''
                    echo "PATH = ${PATH}"
                    echo "M2_HOME = ${M2_HOME}"
                   '''
            }
        }
        stage('Git Clone') {
            steps {
                git credentialsId: 'Git_cred', url: 'https://github.com/nudieyi/maven-web-app.git'
            }
        }

        stage('Maven Build') {
            steps {
               sh "mvn clean install" 
            }
        }

        stage('Code Quality') {
            steps {
                withSonarQubeEnv(credentialsId: 'jenkins-sonar', installationName: 'SQ1') {
                    sh "mvn sonar:sonar"
                }
            }
        }

        stage('Nexus Artifactory') {
            steps {
                script {
                    nexusArtifactUploader(
                        nexusVersion: 'nexus3',
                        protocol: 'http',
                        nexusUrl: 'http://172.31.2.45:8081',
                        groupId: 'com.mt',
                        version: '1.0.0',
                        repository: 'http://172.31.2.45:8081/repository/testapp-release/',
                        credentialsId: 'Nexus_cred',
                        artifacts: [
                            [artifactId: 'maven-web-application', file: 'target/maven-web-application-1.0.0.war', type: 'war']
                        ]
                    )
                }
            }
        }

        stage('Docker Build') {
            steps {
                sh 'docker build -t nudieyi/maven-web-app2 .'
            }
        }

        stage('Docker Push') {
            steps {
                withCredentials([string(credentialsId: 'DH_Cred', variable: 'DOCKER_HUB_CRED')]) {
                    sh "docker login -u nudieyi -p ${DOCKER_HUB_CRED}"
                    sh 'docker push nudieyi/maven-web-app2'
                }
            }
        }

        stage('Deploy to Tomcat') {
            steps {
                script {
                    deploy adapters: [tomcat9(credentialsId: 'Tomcat_Cred.', path: '', url: 'http://172.31.23.21:8080/')],
                        contextPath: null,
                        war: 'target/*.war'
                }
            }
        }
      }
    }


\[WARNING\] Parameter 'sonar.host.url' is unknown for plugin 'sonar-maven-plugin:3.7.0.1746:sonar (default-cli)'
\[WARNING\] Parameter 'sonar.login' is unknown for plugin 'sonar-maven-plugin:3.7.0.1746:sonar (default-cli)'
\[INFO\]
\[INFO\] --- sonar:3.7.0.1746:sonar (default-cli) @ maven-web-application ---
\[INFO\] User cache: /var/lib/jenkins/.sonar/cache
\[INFO\] SonarQube version: 7.8.0
\[INFO\] Default locale: "en", source code encoding: "UTF-8"
\[INFO\] Load global settings
\[INFO\] ------------------------------------------------------------------------
\[INFO\] BUILD FAILURE
\[INFO\] ------------------------------------------------------------------------
\[INFO\] Total time:  1.679 s
\[INFO\] Finished at: 2023-11-24T02:51:31Z
\[INFO\] ------------------------------------------------------------------------
\[ERROR\] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project maven-web-application: Not authorized. Please check the properties sonar.login and sonar.password. -\> \[Help 1\]
\[ERROR\]
\[ERROR\] To see the full stack trace of the errors, re-run Maven with the -e switch.
\[ERROR\] Re-run Maven using the -X switch to enable full debug logging.
\[ERROR\]
\[ERROR\] For more information about the errors and possible solutions, please read the following articles:
\[ERROR\] \[Help 1\] <http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException>
\[Pipeline\] }
WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeed?

0

There are 0 answers