forked from boschresearch/pylife
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
133 lines (129 loc) · 4.22 KB
/
Jenkinsfile
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import hudson.tasks.junit.TestResultSummary
// SonarQube related variable - FEEL FREE TO MODIFY
BASE_BRANCH_NAME = "develop"
// SonarQube related variables
SONAR_PROPERTY_FILE = "sonar-project.properties"
CURRENT_BRANCH_NAME = env.BRANCH_NAME
PR_KEY = env.CHANGE_ID
SONARQUBE_SERVER_ID = "SonarqubeMSO"
@Library('create-jenkins-library') _
pipeline {
// Which Build Node?
agent any
// Discard the old builds and artifacts
options {
buildDiscarder logRotator(
artifactDaysToKeepStr: '30',
artifactNumToKeepStr: '1',
daysToKeepStr: '30',
numToKeepStr: '10'
)
}
// Build stages
stages {
// Create a new Anaconda python virtual environment and install PIP packages
stage('Prepare Python env') {
steps {
bat 'install_pylife_win.bat'
}
}
// Test Python packages with PyTest
stage('PyTest') {
steps {
// Running unit tests
bat 'batch_scripts/run_pylife_tests.bat'
}
}
// Static code analysis with Flake8
stage('Flake8') {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
bat 'batch_scripts/run_code_analysis.bat'
}
}
}
// Building documentation
stage('Documentation') {
steps {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
bat 'batch_scripts/build_docs.bat'
}
}
}
stage ('Publish Test Results') {
steps {
// JUnit Test results
junit 'junit.xml'
//Publish
publishHTML target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'coverage_report',
reportFiles: 'index.html',
reportName: 'Test coverage'
]
}
}
stage ('Publish coverage report') {
steps{
script {
cobertura(
coberturaReportFile: "coverage_report.xml",
onlyStable: false,
failNoReports: true,
failUnhealthy: false,
failUnstable: false,
autoUpdateHealth: true,
autoUpdateStability: true,
zoomCoverageChart: true,
maxNumberOfBuilds: 0,
lineCoverageTargets: '75, 75, 75',
conditionalCoverageTargets: '75, 75, 75',
classCoverageTargets: '75, 75, 75',
methodCoverageTargets: '75, 75, 75',
fileCoverageTargets: '75, 75, 75',
)
}
}
}
stage ('Publish documentation') {
steps{
publishHTML target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'docs/_build/',
reportFiles: 'index.html',
reportName: 'Documentation'
]
}
}
stage ('SonarQube analysis') {
steps {
sonarScanner (
sonarqubeServerID: SONARQUBE_SERVER_ID,
currentBranchName: CURRENT_BRANCH_NAME,
sonarBaseBranchName: BASE_BRANCH_NAME,
prKey: PR_KEY,
workSpacePath: env.WORKSPACE
)
}
}
}
// Post-build actions
post {
always {
// Sending emails to developers & Culprits & Requester
script {
emailext body: '''${SCRIPT, template="groovy-html.template"}''',
mimeType: 'text/html',
subject: "[Jenkins] ${currentBuild.result}: '${env.JOB_NAME} [Build #${env.BUILD_NUMBER}]'",
recipientProviders: [
[$class: 'CulpritsRecipientProvider'],
[$class: 'RequesterRecipientProvider']
]
}
}
}
}