-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathJenkinsfile
215 lines (198 loc) · 10.6 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
def sendFailEmail(){
// modify fail email recipient
def failRecipient = "[email protected]"
def subject = "FAILURE: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'"
def summary = "${subject} (${env.BUILD_URL})"
def details = """
FAILURE: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':
Check console output at "${env.JOB_NAME} [${env.BUILD_NUMBER}] (${env.BUILD_URL})"
"""
emailext(
to: failRecipient,
recipientProviders: [culprits()],
subject: subject,
body: details
)
}
def notifyBuild(String buildStatus = 'STARTED',stageName) {
// modify build status email recipient
def buildStatusRecipient = "[email protected]"
// default stauts
buildStatus = buildStatus ?: 'SUCCESSFUL'
def subject = "${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'"
def summary = "${subject} (${env.BUILD_URL})"
def details = """
${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':
Stage: ${stageName}
Check console output at "${env.JOB_NAME} [${env.BUILD_NUMBER}] (${env.BUILD_URL})"
"""
emailext (
subject: subject,
body: details,
to: buildStatusRecipient
)
}
pipeline {
agent {
label 'GPU-Monet'
}
options {
timeout(time: 1, unit: 'HOURS')
}
environment {
GIT_URL = "[email protected]:AI-Platform/TensorGraph.git"
}
stages {
stage('Clone & update repos') {
steps {
script{
stageName = 'Clone & update repos'
try {
// notifyBuild('STARTED',stageName)
checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '${ghprbActualCommit}']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '5744d880-cfb2-4925-b24a-8d5812f7dcad', name: 'tensorgraph', refspec: '+refs/pull/*/head:refs/remotes/origin/pr/*', url: '[email protected]:AI-Platform/TensorGraph.git']]]
//git branch: 'develop', credentialsId: '5744d880-cfb2-4925-b24a-8d5812f7dcad', url: GIT_URL
} catch (e) {
currentBuild.result = "FAILED"
notifyBuild(currentBuild.result, stageName)
throw e
}
// finally {
// notifyBuild(currentBuild.result, stageName)
// }
}
}
}
stage('Parallel running'){
parallel {
stage('SonarQube'){
stages{
stage('Static Code Analysis') {
steps{
// requires SonarQube Scanner
withSonarQubeEnv('sonar.skymed.ai') {
sh '''
/opt/sonar-scanner/bin/sonar-scanner -X \
-Dsonar.projectKey=tensorgraph \
-Dsonar.sources=. \
-Dsonar.host.url=https://sonar.skymed.ai \
-Dsonar.login=b6252cd52eb8c205c39c3900a5364548b8c4502e
'''
}
}
}
stage('Code Quality Gate') {
options {
timeout(time: 1, unit: 'HOURS')
}
steps {
script{
def qualitygate = waitForQualityGate()
def failmsg = """
Pipeline aborted due to
quality gate failure:
${qualitygate.status}
Access to SonarQube dashboard
(https://sonar.skymed.ai/dashboard?id=tensorgraph)
to understand the warnings.
"""
if (qualitygate.status != "OK") {
echo failmsg
currentBuild.result = "FAILED"
stageName = 'Code Quality Gate'
notifyBuild(currentBuild.result, stageName)
error "Pipeline aborted due to quality gate failure: ${qualitygate.status}"
}
}
}
}
}
}
stage('Workflow'){
stages{
stage('environment setup') {
steps {
script {
stageName = 'environment setup'
try {
//sh 'apt-get update && apt-get install -y python-pip python3-pip'
//sh 'pip install --no-cache-dir --only-binary=numpy,scipy numpy nose scipy sklearn --user'
//sh 'pip install --no-cache-dir tensorflow --user'
//sh 'pip3 install --no-cache-dir --only-binary=numpy,scipy numpy nose scipy sklearn --user'
//sh 'pip3 install --no-cache-dir tensorflow --user'
//sh "pip3 install -U pytest pytest-cov pytest-metadata pytest-qt PyQt5 pytest-xvfb pytest-remotedata>=0.3.1 --user"
//sh "pip install -U pytest pytest-cov pytest-metadata pytest-qt PyQt5 pytest-xvfb pytest-remotedata>=0.3.1 --user"
//sh 'python -m pytest --cov=tensorgraph test/'
sh 'mkdir -p test-report'
//sh 'python3 -m pytest --cov=tensorgraph --cov-report=xml:test-report/coverage.xml test/'
} catch (e) {
currentBuild.result = "FAILED"
notifyBuild(currentBuild.result,stageName)
throw e
}
}
}
}
stage('Run python3 pytest') {
steps {
script {
stageName = 'Run python3 pytest'
try {
//sh 'apt-get update && apt-get install -y python-pip python3-pip'
//sh 'pip install --no-cache-dir --only-binary=numpy,scipy numpy nose scipy pytest sklearn --user'
//sh 'pip install --no-cache-dir tensorflow --user'
//sh 'pip3 install --no-cache-dir --only-binary=numpy,scipy numpy nose scipy pytest sklearn --user'
//sh 'pip3 install --no-cache-dir tensorflow --user'
//sh "pip3 install -U pytest-cov pytest-metadata pytest-qt PyQt5 pytest-xvfb pytest-remotedata>=0.3.1 --user"
//sh "pip install -U pytest pytest-cov pytest-metadata pytest-qt PyQt5 pytest-xvfb pytest-remotedata>=0.3.1 --user"
//sh 'python -m pytest --cov=tensorgraph test/'
//sh 'mkdir -p test-report'
sh 'python3 -m pytest --cov=tensorgraph --cov-report=xml:test-report/coverage.xml test/'
} catch (e) {
currentBuild.result = "FAILED"
notifyBuild(currentBuild.result,stageName)
throw e
}
}
}
}
stage('Run python2 pytest') {
steps {
script {
stageName = 'Run python2 pytest'
try {
//sh 'apt-get update && apt-get install -y python-pip python3-pip'
//sh 'pip install --no-cache-dir --only-binary=numpy,scipy numpy nose scipy pytest sklearn --user'
//sh 'pip install --no-cache-dir tensorflow --user'
//sh 'pip3 install --no-cache-dir --only-binary=numpy,scipy numpy nose scipy pytest sklearn --user'
//sh 'pip3 install --no-cache-dir tensorflow --user'
//sh "pip3 install -U pytest-cov pytest-metadata pytest-qt PyQt5 pytest-xvfb pytest-remotedata>=0.3.1 --user"
//sh "pip install -U pytest pytest-cov pytest-metadata pytest-qt PyQt5 pytest-xvfb pytest-remotedata>=0.3.1 --user"
sh 'python -m pytest test/'
//sh 'mkdir -p test-report'
//sh 'python3 -m pytest --cov=tensorgraph --cov-report=xml:test-report/coverage.xml test/'
} catch (e) {
currentBuild.result = "FAILED"
notifyBuild(currentBuild.result,stageName)
throw e
}
}
}
}
}
}
}
}
}
post {
success {
echo 'I succeeeded!'
}
failure {
echo 'I failed :('
sendFailEmail()
}
unstable {
echo 'I am unstable :/'
}
}
}