-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile_multi_branch.groovy
80 lines (68 loc) · 1.92 KB
/
Jenkinsfile_multi_branch.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
@Library('shared-library') _
import com.davidleonm.WeatherStationSensorsReaderVariables
pipeline {
agent { label 'slave' }
stages {
stage('Prepare Python ENV') {
steps {
script {
setBuildStatus('pending', "${WeatherStationSensorsReaderVariables.RepositoryName}")
// Clean & Prepare new python environment
sh '''
rm -rf ENV
python3 -m venv ENV
ENV/bin/pip install --no-cache-dir --upgrade pip
ENV/bin/pip install --no-cache-dir --upgrade wheel
ENV/bin/pip install --no-cache-dir --upgrade setuptools
ENV/bin/pip install --no-cache-dir psycopg2 gpiozero coverage
'''
}
}
}
stage('Execute unit tests and code coverage') {
steps {
script {
sh """
ENV/bin/python -m unittest discover -s ${WORKSPACE}/WeatherStationSensorsReader
ENV/bin/coverage run -m unittest discover -s ${WORKSPACE}/WeatherStationSensorsReader
"""
}
}
}
stage('SonarQube analysis') {
environment {
def scannerHome = tool 'Sonarqube'
}
steps {
script {
sh "ENV/bin/coverage xml"
}
withSonarQubeEnv('Sonarqube') {
sh "${scannerHome}/bin/sonar-scanner"
}
timeout(time: 10, unit: 'MINUTES') {
waitForQualityGate abortPipeline: true
}
}
}
stage('Deploy on staging') {
steps {
script {
deployContainerOnDockerHub("${WeatherStationSensorsReaderVariables.DockerHubStagingRegistryName}")
}
}
}
}
post {
success {
script {
setBuildStatus('success', "${WeatherStationSensorsReaderVariables.RepositoryName}")
}
}
failure {
script {
setBuildStatus('failure', "${WeatherStationSensorsReaderVariables.RepositoryName}")
}
}
}
}