Skip to content

sonarExecuteScan

Executes the Sonar scanner

Description

The step executes the sonar-scanner cli command to scan the defined sources and publish the results to a SonarQube instance.

Usage

We recommend to define values of step parameters via config.yml file. In this case, calling the step is reduced to one simple line.
Calling the step can be done either via the Jenkins library step or on the command line.

Jenkins pipelines

sonarExecuteScan script: this

Command line

piper sonarExecuteScan

Outputs

Output type Details
influx measurement step_data
  • sonar

Prerequisites

  • The project needs a sonar-project.properties file that describes the project and defines certain settings, see here.
  • A SonarQube instance needs to be defined in the Jenkins.

Parameters

Overview

Name Mandatory Additional information
script yes Jenkins only reference to Jenkins main pipeline script
branchName no
changeBranch no
changeId no
changeTarget no
containerCommand no Jenkins only
containerShell no Jenkins only
coverageExclusions no
customTlsCertificateLinks no
disableInlineComments no
dockerEnvVars no Jenkins only
dockerImage no Jenkins only
dockerName no Jenkins only
dockerOptions no Jenkins only
dockerPullImage no Jenkins only
dockerVolumeBind no Jenkins only
dockerWorkspace no Jenkins only
githubApiUrl no
githubToken no Secret pass via ENV or Jenkins credentials (githubTokenCredentialsId)
host no
inferBranchName no
inferJavaBinaries no
inferJavaLibraries no
instance no
legacyPRHandling no
m2Path no
options no
organization no
owner no
projectKey no
projectVersion no
pullRequestProvider no
repository no
sonarScannerDownloadUrl no
token no Secret pass via ENV or Jenkins credentials (sonarTokenCredentialsId)
verbose no activates debug output

Details

branchName

Non-Pull-Request only: Name of the SonarQube branch that should be used to report findings to.

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default $PIPER_branchName (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

changeBranch

Pull-Request only: The name of the pull-request branch.

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default $PIPER_changeBranch (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☐ steps
  • ☐ stages
Resource references none

changeId

Pull-Request only: The id of the pull-request.

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default $PIPER_changeId (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☐ steps
  • ☐ stages
Resource references none

changeTarget

Pull-Request only: The name of the base branch.

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default $PIPER_changeTarget (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☐ steps
  • ☐ stages
Resource references none

containerCommand

Jenkins-specific: Used for proper environment setup.

Kubernetes only: Allows to specify start command for container created with dockerImage parameter to overwrite Piper default (/usr/bin/tail -f /dev/null).

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

containerShell

Jenkins-specific: Used for proper environment setup.

Allows to specify the shell to be executed for container with containerName.

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

coverageExclusions

A list of patterns that should be excluded from the coverage scan.

back to overview

Scope Details
Aliases -
Type []string
Mandatory no
Default $PIPER_coverageExclusions (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

List of download links to custom TLS certificates. This is required to ensure trusted connections to instances with custom certificates.

back to overview

Scope Details
Aliases -
Type []string
Mandatory no
Default $PIPER_customTlsCertificateLinks (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

disableInlineComments

Pull-Request only: Disables the pull-request decoration with inline comments. DEPRECATED: only supported in SonarQube < 7.2

back to overview

Scope Details
Aliases -
Type bool
Mandatory no
Default false
Possible values - true
- false
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

dockerEnvVars

Jenkins-specific: Used for proper environment setup.

Environment variables to set in the container, e.g. [http_proxy: "proxy:8080"].

back to overview

Scope Details
Aliases -
Type map[string]string
Mandatory no
Default
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

dockerImage

Jenkins-specific: Used for proper environment setup.

Name of the docker image that should be used. If empty, Docker is not used and the command is executed directly on the Jenkins system.

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

dockerName

Jenkins-specific: Used for proper environment setup.

Kubernetes only: Name of the container launching dockerImage. SideCar only: Name of the container in local network.

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

dockerOptions

Jenkins-specific: Used for proper environment setup.

Docker options to be set when starting the container.

back to overview

Scope Details
Aliases -
Type []string
Mandatory no
Default
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

dockerPullImage

Jenkins-specific: Used for proper environment setup.

Set this to 'false' to bypass a docker image pull. Usefull during development process. Allows testing of images which are available in the local registry only.

back to overview

Scope Details
Aliases -
Type bool
Mandatory no
Default false
Possible values - true
- false
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

dockerVolumeBind

Jenkins-specific: Used for proper environment setup.

Volumes that should be mounted into the docker container.

back to overview

Scope Details
Aliases -
Type map[string]string
Mandatory no
Default
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

dockerWorkspace

Jenkins-specific: Used for proper environment setup.

Kubernetes only: Specifies a dedicated user home directory for the container which will be passed as value for environment variable HOME.

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

githubApiUrl

Pull-Request only: The URL to the Github API. See GitHub plugin docs DEPRECATED: only supported in SonarQube < 7.2

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default https://api.github.com
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

githubToken

Pull-Request only: Token for Github to set status on the Pull-Request.

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default $PIPER_githubToken (if set)
Secret yes
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☐ steps
  • ☐ stages
Resource references Jenkins credential id:
  id: githubTokenCredentialsId
  reference to: ``

host

The URL to the Sonar backend.

back to overview

Scope Details
Aliases sonarServerUrl
Type string
Mandatory no
Default $PIPER_host (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

inferBranchName

Jenkins only: Whether to infer the branchName parameter automatically based on the BRANCH_NAME environment variable in non-productive runs of the pipeline.

back to overview

Scope Details
Aliases -
Type bool
Mandatory no
Default false
Possible values - true
- false
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

inferJavaBinaries

Find the location of generated Java class files in all modules and pass the option `sonar.java.binaries to the sonar tool.

back to overview

Scope Details
Aliases -
Type bool
Mandatory no
Default false
Possible values - true
- false
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

inferJavaLibraries

If the parameter m2Path is configured for the step mavenExecute in the general section of the configuration, pass it as option sonar.java.libraries to the sonar tool.

back to overview

Scope Details
Aliases -
Type bool
Mandatory no
Default false
Possible values - true
- false
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

instance

Jenkins only: The name of the SonarQube instance defined in the Jenkins settings. DEPRECATED: use host parameter instead

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default SonarCloud
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

legacyPRHandling

Pull-Request only: Activates the pull-request handling using the GitHub Plugin. DEPRECATED: only supported in SonarQube < 7.2

back to overview

Scope Details
Aliases -
Type bool
Mandatory no
Default false
Possible values - true
- false
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

m2Path

Path to the location of the local repository that should be used.

back to overview

Scope Details
Aliases maven/m2Path
Type string
Mandatory no
Default $PIPER_m2Path (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

options

A list of options which are passed to the sonar-scanner.

back to overview

Scope Details
Aliases sonarProperties (deprecated)
Type []string
Mandatory no
Default $PIPER_options (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

organization

SonarCloud.io only: Organization that the project will be assigned to in SonarCloud.io.

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default $PIPER_organization (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

owner

Pull-Request only: The owner of the scm repository.

back to overview

Scope Details
Aliases githubOrg
Type string
Mandatory no
Default $PIPER_owner (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references commonPipelineEnvironment:
  reference to: github/owner

projectKey

The project key identifies the project in SonarQube.

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default $PIPER_projectKey (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

projectVersion

The project version that is reported to SonarQube.

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default $PIPER_projectVersion (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references commonPipelineEnvironment:
  reference to: artifactVersion

pullRequestProvider

Pull-Request only: The scm provider.

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default GitHub
Possible values - GitHub
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

repository

Pull-Request only: The scm repository.

back to overview

Scope Details
Aliases githubRepo
Type string
Mandatory no
Default $PIPER_repository (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references commonPipelineEnvironment:
  reference to: github/repository

script

Jenkins-specific: Used for proper environment setup.

The common script environment of the Jenkinsfile running. Typically the reference to the script calling the pipeline step is provided with the this parameter, as in script: this. This allows the function to access the commonPipelineEnvironment for retrieving, e.g. configuration parameters.

back to overview

Scope Details
Aliases -
Type Jenkins Script
Mandatory yes
Default
Secret no
Configuration scope
  • ☐ parameter
  • ☐ general
  • ☐ steps
  • ☐ stages
Resource references none

sonarScannerDownloadUrl

URL to the sonar-scanner-cli archive.

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.4.0.2170-linux.zip
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

token

Token used to authenticate with the Sonar Server.

back to overview

Scope Details
Aliases sonarToken
Type string
Mandatory no
Default $PIPER_token (if set)
Secret yes
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☐ steps
  • ☐ stages
Resource references Jenkins credential id:
  id: sonarTokenCredentialsId
  reference to: ``

verbose

verbose output

back to overview

Scope Details
Aliases -
Type bool
Mandatory no
Default false
Possible values - true
- false
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

sonarTokenCredentialsId

Jenkins-specific: Used for proper environment setup.

Jenkins 'Secret text' credentials ID containing the token used to authenticate with the Sonar Server.

back to overview

Scope Details
Aliases -
Type string
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages

githubTokenCredentialsId

Jenkins-specific: Used for proper environment setup.

Jenkins 'Secret text' credentials ID containing the token used to authenticate with the Github Server.

back to overview

Scope Details
Aliases -
Type string
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages

Exceptions

none

Examples