Jenkins/vars/sonarqube.groovy

81 lines
3.5 KiB
Groovy
Raw Normal View History

2021-06-11 09:34:56 +02:00
// Pipeline de scan de projet avec SonarQube
def call() {
pipeline {
agent {
label 'docker'
}
2023-05-03 15:58:38 +02:00
2021-06-11 09:34:56 +02:00
environment {
2023-05-03 15:58:38 +02:00
projectDir = "${env.project_name}_${env.BUILD_ID}"
2021-06-11 09:34:56 +02:00
}
stages {
stage("Package project") {
when {
not {
triggeredBy 'TimerTrigger'
}
}
steps {
script {
stage("Clone repository") {
2023-05-03 15:58:38 +02:00
checkout scm:
2021-06-11 09:34:56 +02:00
[
2023-05-03 15:58:38 +02:00
$class: 'GitSCM',
userRemoteConfigs: [[url: env.repository_url, credentialsId: 'jenkins-ssh-mse']],
2021-06-11 09:34:56 +02:00
branches: [[name: env.ref]],
extensions: [
[$class: 'RelativeTargetDirectory', relativeTargetDir: env.projectDir ],
[$class: 'CloneOption', noTags: false, shallow: false, depth: 0, reference: ''],
[$class: 'WipeWorkspace' ]
]
2023-05-03 15:58:38 +02:00
],
changelog: false,
2021-06-11 09:34:56 +02:00
poll: false
}
2023-05-03 15:58:38 +02:00
2021-06-11 09:34:56 +02:00
stage("Scan project") {
dir(env.projectDir) {
withCredentials([
string(credentialsId: 'SONARQUBE_URL', variable: 'SONARQUBE_URL'),
string(credentialsId: 'SONARQUBE_TOKEN', variable: 'SONARQUBE_TOKEN'),
]) {
sh """
docker run \
--rm \
-e SONAR_HOST_URL="${env.SONARQUBE_URL}" \
-e SONAR_LOGIN="${env.SONARQUBE_TOKEN}" \
-v "${env.WORKSPACE}/${env.projectDir}/:/usr/src" \
sonarsource/sonar-scanner-cli \
-Dsonar.projectKey=${env.sonarqubeProjectKey} \
-Dsonar.projectVersion=${env.ref}
"""
}
// On notifie le canal Rocket.Chat du scan
// rocketSend (
// avatar: 'https://jenkins.cadol.es/static/b5f67753/images/headshot.png',
// message: """
// Le projet ${env.project_name} a été scanné par SonarQube.
2023-05-03 15:58:38 +02:00
2021-06-11 09:34:56 +02:00
// - [Voir les résultats](${env.SONARQUBE_URL}/dashboard?id=${env.sonarqubeProjectKey})
// - [Visualiser le job](${env.RUN_DISPLAY_URL})
2023-05-03 15:58:38 +02:00
2021-06-11 09:34:56 +02:00
// @${env.sender_login}
// """.stripIndent(),
// rawMessage: true,
2023-05-03 15:58:38 +02:00
// )
2021-06-11 09:34:56 +02:00
}
}
}
}
post {
always {
sh "rm -rf '${env.projectDir}'"
}
}
}
}
}
2023-05-03 15:58:38 +02:00
}