GhostDonkeys
GhostDonkeys

Reputation: 57

Jenkins Pipeline SonarQube key name

When building a multibranch pipeline, I send each of my projects to SonarQube using the SonarQube plugin like so:

pipeline {
    agent any

    options {
        buildDiscarder(logRotator(numToKeepStr:'20'))
        timeout(time: 30, unit: 'MINUTES')
    }

    tools {
    maven 'Maven 3.3.9'
    jdk   'JDK 1.8'
    }


    stages {
        stage('Checkout') {
            steps {
                echo 'Checking out..'
                checkout scm
                echo "My branch is: ${env.BRANCH_NAME}"
            }
        }

        stage('Build') {
            steps {
                echo 'Building..'
                bat 'mvn clean verify -P!local'
            }
        }

        stage('SonarQube analysis'){
            steps{
                echo 'Analysing...'
                withSonarQubeEnv('SonarQube') {
                    bat 'mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar'
                }
            }
        }
    }
}

It works fine, but one thing I need it to do is to change the name of the project in SonarQube to be projectName/builtBranch instead of just the project name. Is there a way I can do this using the pipeline?

Upvotes: 1

Views: 2671

Answers (1)

Christopher Orr
Christopher Orr

Reputation: 111575

This doesn't seem to be a Jenkins issue; rather you should be able to set the various sonar.* properties (e.g. sonar.projectName or sonar.branch) when running the Maven plugin.

The documentation seems to have a full list: https://docs.sonarqube.org/display/SONAR/Analysis+Parameters

Upvotes: 2

Related Questions