My gradle scan is failing when run through the jenkins pipeline

I am trying to run a gradle scan via a jenkins pipeline. What I am trying to do is achieve the alternate to sonar’s build breaker functionality.
I followed all the steps mentioned here

https://blog.sonarsource.com/breaking-the-sonarqube-analysis-with-jenkins-pipelines

and this is my pipeline script

node {
  stage('SCM') {
    git 'https://github.com/SonarSource/sonar-scanning-examples.git'
  }
  stage('go to cloned dir') {
        sh """
                cd $WORKSPACE/sonarqube-scanner-gradle/gradle-basic
            """
    }
  stage('build & SonarQube Scan') {
    withSonarQubeEnv('sonarhost') {
      sh 'gradle tasks --all'
      sh 'gradle --scan sonarqube -D "sonar.projectKey=sonarbbtest"'
    } // SonarQube taskId is automatically attached to the pipeline context
  }
}
 
// No need to occupy a node
stage("Quality Gate") {
  timeout(time: 1, unit: 'HOURS') { // Just in case something goes wrong, pipeline will be killed after a timeout
    def qg = waitForQualityGate() // Reuse taskId previously collected by withSonarQubeEnv
    if (qg.status != 'OK') {
      error "Pipeline aborted due to quality gate failure: ${qg.status}"
    }
  }
}

My pipeline is failing currently at the “build & SonarQube Scan” with the error as
FAILURE: Build failed with an exception.


* Where:
Auto-applied by using --scan

* What went wrong:
Plugin [id: 'com.gradle.build-scan', version: '2.0.2', artifact: 'com.gradle:build-scan-plugin:2.0.2'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'com.gradle:build-scan-plugin:2.0.2')
  Searched in the following repositories:
    Gradle Central Plugin Repository

My project is same as given in the link
https://github.com/SonarSource/sonar-scanning-examples.git
Gradle version is 5

Try to change sh 'gradle --scan sonarqube -D "sonar.projectKey=sonarbbtest"' to sh 'gradle -D"sonar.projectKey=sonarbbtest" sonarqube'

1 Like