Reputation:
How to get sonar environment variables like sonar host, sonar project key or sonar workspace in order to use them in email with Jenkins plugin: Editable Email Notification.
any help or idea ?
Upvotes: 4
Views: 8473
Reputation: 18507
As @chizou explains, you can use withSonarQubeEnv()
to get environment values to use in your pipeline. I only want to add more information, however I want to add extra information on how to use it.
In Jenkins sonar plugins source code you can see that that the available variables injected will be:
This variables are configured from jenkins manager, and SONAR_EXTRA_PROPS
is a custom parameter where you can add key=vaule
pairs separated by coma.
To use in scripted pipeline:
pipeline {
agent any
stages {
stage('Hello') {
steps {
withSonarQubeEnv('Sonarqube') {
script{
// check the SONAR_ variables in all environment vars
def output = sh(returnStdout: true, script: 'env')
echo "Output: ${output}"
// or use directly
echo "${env.SONAR_HOST_URL}"
echo "${env.SONAR_CONFIG_NAME}"
}
}
}
}
}
}
Upvotes: 0
Reputation: 1272
you can use the withSonarQubeEnv()
plugin function to pull the values. You have to configure Jenkins with the Sonar variables you want it to use. You can find more info about that at the link below. Unfortunately, I can't seem to find documentation from Sonarqube what variables are being provided. You might want to run something like sh "env"
within the withSonarQubeEnv
stanza to get an idea.
Upvotes: 3