Browse Source

Add Jenkinsfile

Johann Schmitz 1 year ago
parent
commit
c0c27fbf08
Signed by: Johann Schmitz <johann@j-schmitz.net> GPG Key ID: A084064277C501ED
1 changed files with 58 additions and 0 deletions
  1. 58
    0
      Jenkinsfile

+ 58
- 0
Jenkinsfile View File

@@ -0,0 +1,58 @@
1
+node {
2
+	try {
3
+		checkout scm
4
+		updateGitlabCommitStatus name: 'jenkins', state: 'running'
5
+
6
+		docker.withRegistry('https://registry.docks.ercpe.de', 'docker-registry') {
7
+			docker.image('python:3.4').inside {
8
+				stage("Install dependencies") {
9
+					sh "make install_deps"
10
+				}
11
+
12
+				stage("Compile") {
13
+					sh "make compile compile_optimized"
14
+				}
15
+
16
+				stage("Run tests") {
17
+					sh "make test"
18
+				}
19
+
20
+				stage("Run coverage") {
21
+					sh "make coverage"
22
+				}
23
+
24
+				stage("Run pylint") {
25
+					sh "pylint -r n --msg-template='{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}' > pylint-report.txt || true"
26
+				}
27
+			}
28
+
29
+			withCredentials([[
30
+				$class: 'UsernamePasswordMultiBinding',
31
+				credentialsId: 'sonar',
32
+				usernameVariable: 'USERNAME',
33
+				passwordVariable: 'PASSWORD']]) {
34
+
35
+				docker.image('ercpe/sonar-scanner:latest').inside {
36
+					stage("Run sonar-scanner") {
37
+						sh "sonar-scanner -Dsonar.host.url=${SONAR_HOST} -Dsonar.login=${USERNAME} -Dsonar.password=${PASSWORD}"
38
+					}
39
+				}
40
+			}
41
+		}
42
+
43
+		updateGitlabCommitStatus name: 'jenkins', state: 'success'
44
+	} catch (e) {
45
+    	currentBuild.result = "FAILED"
46
+		updateGitlabCommitStatus name: 'jenkins', state: 'failed'
47
+    	notifyFailedBuild()
48
+    	throw e
49
+	}
50
+}
51
+
52
+def notifyFailedBuild() {
53
+  emailext (
54
+      subject: "FAILED: ${env.JOB_NAME} [${env.BUILD_NUMBER}]",
55
+      body: """Job ${env.JOB_NAME} [${env.BUILD_NUMBER}] has FAILED: ${env.BUILD_URL}""",
56
+      recipientProviders: [[$class: 'CulpritsRecipientProvider']]
57
+    )
58
+}