简体   繁体   中英

Sonarqube-Jenkins-maven Intergate

Please check my new pipeline is : now it is intergrating with maven. NEW PIPELINE-

 stage('Test & code quality check ') {
      withMaven(maven: 'M3'){
    withSonarQubeEnv(credentialsId:'mbk-sonar',installationName:'sonar-qube') {
        sh '''mvn sonar:sonar -X  -f  /var/jenkins_home/workspace/cabs-stag/cabs-stagSrc/pom.xml \
  -Dsonar.projectKey=mobikwik-jenkins \
  -Dsonar.projectName=mobikwik-jenkins \
  -Dsonar.host.url=http://10.20.15.26:9000 \
  -Dsonar.sourceEncoding=UTF-8 \
  -Dsonar.language=java \
  -Dsonar.sources=/var/jenkins_home/workspace/cabs-stag/cabs-stagSrc/shared-objects/src/main/ '''
    }
      }
  }

ERROR: enter image description here

This error is coming because jenkins is not able to recognise maven.

Pre-requisite: You must have configured Sonarqube with Jenkins.

Follow the following steps to rectify your issue:

  1. Download the Maven plugin in Jenkins or if you have already downloaded skip to next step.

  2. In the Manage Jenkins >> Global Tool Configuration >> Maven , setup the MAVEN HOME path if you have download the maven binaries or select install automatically. Give any name. 在此处输入图片说明

  3. Go to Jenkins pipeline script and the maven tool. Use like this:

     pipeline { agent any tools { maven 'Maven' } stages { stage ('Initialize') { steps { sh ''' echo "PATH = ${PATH}" echo "M2_HOME = ${M2_HOME}" ''' } } stage ('Build') { steps { echo 'This is a minimal pipeline.' sh 'mvn clean install' } } stage('SonarCloud') { withSonarQubeEnv(credentialsId:'mbksonar',installationName:'sonar-qube') { sh '''mvn sonar:sonar \\ -Dsonar.projectKey=XU6rO8Zce5RaXOtIiWF0dEbmscjiM8qX \\ -Dsonar.host.url=https://sonar.mobikwik.com \\ -Dsonar.sources=src/main \\ -Dsonar.sourceEncoding=UTF-8 \\ -Dsonar.language=java \\ -Dsonar.java.binaries=target/classes \\ -Dsonar.login=jenkins''' } } } }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM