Skip to content

Commit c8005d6

Browse files
committed
Add Jenkins pipeline for performing Sonar analysis
Signed-off-by: Kai Hudalla <[email protected]>
1 parent d9150f1 commit c8005d6

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed

jenkins/Hono-Sonar-Pipeline.groovy

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2021 Contributors to the Eclipse Foundation
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional
5+
* information regarding copyright ownership.
6+
*
7+
* This program and the accompanying materials are made available under the
8+
* terms of the Eclipse Public License 2.0 which is available at
9+
* http://www.eclipse.org/legal/epl-2.0
10+
*
11+
* SPDX-License-Identifier: EPL-2.0
12+
*******************************************************************************/
13+
14+
/**
15+
* Jenkins pipeline script for perfoming Sonar analysis.
16+
*
17+
*/
18+
19+
pipeline {
20+
agent {
21+
kubernetes {
22+
label 'my-agent-pod'
23+
yaml """
24+
apiVersion: v1
25+
kind: Pod
26+
spec:
27+
containers:
28+
- name: maven
29+
image: "maven:3.8-openjdk-11"
30+
tty: true
31+
command:
32+
- cat
33+
volumeMounts:
34+
- mountPath: /home/jenkins
35+
name: "jenkins-home"
36+
- mountPath: /home/jenkins/.ssh
37+
name: "volume-known-hosts"
38+
- name: "settings-xml"
39+
mountPath: /home/jenkins/.m2/settings.xml
40+
subPath: settings.xml
41+
readOnly: true
42+
- name: "settings-security-xml"
43+
mountPath: /home/jenkins/.m2/settings-security.xml
44+
subPath: settings-security.xml
45+
readOnly: true
46+
- name: "m2-repo"
47+
mountPath: /home/jenkins/.m2/repository
48+
- name: "toolchains-xml"
49+
mountPath: /home/jenkins/.m2/toolchains.xml
50+
subPath: toolchains.xml
51+
readOnly: true
52+
env:
53+
- name: "HOME"
54+
value: "/home/jenkins"
55+
resources:
56+
limits:
57+
memory: "6Gi"
58+
cpu: "2"
59+
requests:
60+
memory: "6Gi"
61+
cpu: "2"
62+
volumes:
63+
- name: "jenkins-home"
64+
emptyDir: {}
65+
- name: "m2-repo"
66+
emptyDir: {}
67+
- configMap:
68+
name: known-hosts
69+
name: "volume-known-hosts"
70+
- name: "settings-xml"
71+
secret:
72+
secretName: m2-secret-dir
73+
items:
74+
- key: settings.xml
75+
path: settings.xml
76+
- name: "settings-security-xml"
77+
secret:
78+
secretName: m2-secret-dir
79+
items:
80+
- key: settings-security.xml
81+
path: settings-security.xml
82+
- name: "toolchains-xml"
83+
configMap:
84+
name: m2-dir
85+
items:
86+
- key: toolchains.xml
87+
path: toolchains.xml
88+
"""
89+
}
90+
}
91+
92+
options {
93+
buildDiscarder(logRotator(numToKeepStr: '3'))
94+
disableConcurrentBuilds()
95+
timeout(time: 45, unit: 'MINUTES')
96+
}
97+
98+
triggers {
99+
cron('TZ=Europe/Berlin\n# every night between 2 and 3 AM\nH 2 * * *')
100+
}
101+
102+
stages {
103+
104+
stage('Build and run Sonar analysis on master branch') {
105+
steps {
106+
container('maven') {
107+
echo "checking out branch [master] ..."
108+
checkout([$class : 'GitSCM',
109+
branches : [[name: "refs/heads/master"]],
110+
userRemoteConfigs: [[url: 'https://github.com/eclipse/hono.git']]])
111+
112+
withSonarQubeEnv(credentialsId: 'sonarcloud-token', installationName: 'SonarCloud.io') {
113+
echo "building and running Sonar analysis ..."
114+
sh 'mvn verify sonar:sonar -Djacoco.skip=false -DnoDocker -DcreateJavadoc=true -Dsonar.organization=eclipse -Dsonar.projectKey=org.eclipse.hono '
115+
}
116+
117+
echo "recording JUnit test results ..."
118+
junit '**/surefire-reports/*.xml'
119+
}
120+
}
121+
122+
}
123+
}
124+
/**
125+
post {
126+
fixed {
127+
step([$class : 'Mailer',
128+
notifyEveryUnstableBuild: true,
129+
recipients : 'hono-dev@eclipse.org',
130+
sendToIndividuals : false])
131+
}
132+
failure {
133+
step([$class : 'Mailer',
134+
notifyEveryUnstableBuild: true,
135+
recipients : 'hono-dev@eclipse.org',
136+
sendToIndividuals : false])
137+
}
138+
}
139+
*/
140+
}

0 commit comments

Comments
 (0)