From c8005d65630fc4a9b86085e30981be7b1a3c8dc7 Mon Sep 17 00:00:00 2001 From: Kai Hudalla Date: Mon, 6 Dec 2021 07:52:13 +0100 Subject: [PATCH] Add Jenkins pipeline for performing Sonar analysis Signed-off-by: Kai Hudalla --- jenkins/Hono-Sonar-Pipeline.groovy | 140 +++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 jenkins/Hono-Sonar-Pipeline.groovy diff --git a/jenkins/Hono-Sonar-Pipeline.groovy b/jenkins/Hono-Sonar-Pipeline.groovy new file mode 100644 index 0000000000..40685dc2b5 --- /dev/null +++ b/jenkins/Hono-Sonar-Pipeline.groovy @@ -0,0 +1,140 @@ +/******************************************************************************* + * Copyright (c) 2021 Contributors to the Eclipse Foundation + * + * See the NOTICE file(s) distributed with this work for additional + * information regarding copyright ownership. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ + +/** + * Jenkins pipeline script for perfoming Sonar analysis. + * + */ + +pipeline { + agent { + kubernetes { + label 'my-agent-pod' + yaml """ +apiVersion: v1 +kind: Pod +spec: + containers: + - name: maven + image: "maven:3.8-openjdk-11" + tty: true + command: + - cat + volumeMounts: + - mountPath: /home/jenkins + name: "jenkins-home" + - mountPath: /home/jenkins/.ssh + name: "volume-known-hosts" + - name: "settings-xml" + mountPath: /home/jenkins/.m2/settings.xml + subPath: settings.xml + readOnly: true + - name: "settings-security-xml" + mountPath: /home/jenkins/.m2/settings-security.xml + subPath: settings-security.xml + readOnly: true + - name: "m2-repo" + mountPath: /home/jenkins/.m2/repository + - name: "toolchains-xml" + mountPath: /home/jenkins/.m2/toolchains.xml + subPath: toolchains.xml + readOnly: true + env: + - name: "HOME" + value: "/home/jenkins" + resources: + limits: + memory: "6Gi" + cpu: "2" + requests: + memory: "6Gi" + cpu: "2" + volumes: + - name: "jenkins-home" + emptyDir: {} + - name: "m2-repo" + emptyDir: {} + - configMap: + name: known-hosts + name: "volume-known-hosts" + - name: "settings-xml" + secret: + secretName: m2-secret-dir + items: + - key: settings.xml + path: settings.xml + - name: "settings-security-xml" + secret: + secretName: m2-secret-dir + items: + - key: settings-security.xml + path: settings-security.xml + - name: "toolchains-xml" + configMap: + name: m2-dir + items: + - key: toolchains.xml + path: toolchains.xml +""" + } + } + + options { + buildDiscarder(logRotator(numToKeepStr: '3')) + disableConcurrentBuilds() + timeout(time: 45, unit: 'MINUTES') + } + + triggers { + cron('TZ=Europe/Berlin\n# every night between 2 and 3 AM\nH 2 * * *') + } + + stages { + + stage('Build and run Sonar analysis on master branch') { + steps { + container('maven') { + echo "checking out branch [master] ..." + checkout([$class : 'GitSCM', + branches : [[name: "refs/heads/master"]], + userRemoteConfigs: [[url: 'https://github.com/eclipse/hono.git']]]) + + withSonarQubeEnv(credentialsId: 'sonarcloud-token', installationName: 'SonarCloud.io') { + echo "building and running Sonar analysis ..." + sh 'mvn verify sonar:sonar -Djacoco.skip=false -DnoDocker -DcreateJavadoc=true -Dsonar.organization=eclipse -Dsonar.projectKey=org.eclipse.hono ' + } + + echo "recording JUnit test results ..." + junit '**/surefire-reports/*.xml' + } + } + + } + } +/** + post { + fixed { + step([$class : 'Mailer', + notifyEveryUnstableBuild: true, + recipients : 'hono-dev@eclipse.org', + sendToIndividuals : false]) + } + failure { + step([$class : 'Mailer', + notifyEveryUnstableBuild: true, + recipients : 'hono-dev@eclipse.org', + sendToIndividuals : false]) + } + } +*/ +}