Newer
Older
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
def runQualityTests() {
sshagent(credentials: ['jenkins-worker'], ignoreMissing: true) {
// Determine git refspec, branch, and clone type
git_shallow_clone = true
git_extensions = []
if (env.ghprbActualCommit) {
git_branch = "${ghprbActualCommit}"
refspec = "+refs/pull/${ghprbPullId}/*:refs/remotes/origin/pr/${ghprbPullId}/*"
if (SHARD == "4") {
git_shallow_clone = false
git_extensions.add([$class: 'WipeWorkspace'])
refspec = refspec + " +refs/heads/master:refs/remotes/origin/master"
}
} else {
git_branch = 'master'
refspec = "+refs/heads/master:refs/remotes/origin/master"
}
git_extensions.add([$class: 'CloneOption', honorRefspec: true, noTags: true, shallow: git_shallow_clone ])
checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: git_branch]],
doGenerateSubmoduleConfigurations: false, extensions: git_extensions, submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'jenkins-worker',
refspec: refspec,
url: 'git@github.com:edx/edx-platform.git']]]
sh "bash scripts/all-tests.sh"
stash includes: '**/reports/**/*', name: "${TEST_SUITE}-${SHARD}-reports"
}
}
def qualityTestCleanup() {
archiveArtifacts allowEmptyArchive: true, artifacts: '**/reports/**/*,test_root/log/**/*.log,*.log'
junit 'reports/quality_junitxml/*.xml'
}
pipeline {
agent { label "jenkins-worker" }
options {
timestamps()
timeout(60)
}
stages {
stage('Mark build as pending on Github') {
when {
// Only run github-build-status for master builds
expression { env.ghprbActualCommit == null }
}
steps {
script {
commit_sha = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
build job: 'github-build-status',
parameters: [
string(name: 'GIT_SHA', value: commit_sha),
string(name: 'GITHUB_ORG', value: 'edx'), string(name: 'GITHUB_REPO', value: 'edx-platform'),
string(name: 'TARGET_URL', value: "${BUILD_URL}"),
string(name: 'DESCRIPTION', value: 'Pending'), string(name: 'CONTEXT', value: 'jenkins/quality'),
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
string(name: 'CREATE_DEPLOYMENT', value: 'false'), string(name: 'BUILD_STATUS', value: 'pending')
],
propagate: false, wait: false
}
}
}
stage('Run Tests') {
parallel {
stage("commonlib pylint") {
agent { label "jenkins-worker" }
environment {
TEST_SUITE = "quality"
SHARD = 1
}
steps {
script {
runQualityTests()
}
}
post {
always {
script {
qualityTestCleanup()
}
}
}
}
stage("lms pylint") {
agent { label "jenkins-worker" }
environment {
TEST_SUITE = "quality"
SHARD = 2
}
steps {
script {
runQualityTests()
}
}
post {
always {
script {
qualityTestCleanup()
}
}
}
}
stage("cms/openedx/pavelib pylint") {
agent { label "jenkins-worker" }
environment {
TEST_SUITE = "quality"
SHARD = 3
}
steps {
script {
runQualityTests()
}
}
post {
always {
script {
qualityTestCleanup()
}
}
}
}
stage("Other quality checks") {
agent { label "jenkins-worker" }
environment {
TEST_SUITE = "quality"
SHARD = 4
}
steps {
script {
runQualityTests()
}
}
post {
always {
script {
qualityTestCleanup()
}
}
}
}
}
}
stage('Diff quality') {
when {
// Only run diff quality on PR builds
expression { env.ghprbTargetBranch != null }
}
environment {
TARGET_BRANCH = "origin/${ghprbTargetBranch}"
}
steps {
sshagent(credentials: ['jenkins-worker'], ignoreMissing: true) {
checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: "${ghprbActualCommit}"]],
doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'CloneOption',
honorRefspec: true, noTags: true, shallow: false], [$class: 'WipeWorkspace']], submoduleCfg: [],
userRemoteConfigs: [[credentialsId: 'jenkins-worker',
refspec: "+refs/heads/${ghprbTargetBranch}:refs/remotes/origin/${ghprbTargetBranch} +refs/pull/${ghprbPullId}/*:refs/remotes/origin/pr/${ghprbPullId}/*",
url: 'git@github.com:edx/edx-platform.git']]]
unstash 'quality-1-reports'
unstash 'quality-2-reports'
unstash 'quality-3-reports'
unstash 'quality-4-reports'
sh "./scripts/jenkins-quality-diff.sh"
}
}
post {
always {
qualityTestCleanup()
publishHTML([allowMissing: true, alwaysLinkToLastBuild: false, keepAll: true, reportDir: 'reports/diff_quality',
reportFiles: 'diff_quality_pylint.html, diff_quality_eslint.html', reportName: 'Diff Quality Report', reportTitles: ''])
}
}
}
}
post {
always {
script{
try {
unstash 'quality-1-reports'
unstash 'quality-2-reports'
unstash 'quality-3-reports'
unstash 'quality-4-reports'
// Check for warnings
warnings canComputeNew: false, canResolveRelativePaths: false, canRunOnFailed: true, categoriesPattern: '',
defaultEncoding: '', excludePattern: '', healthy: '', includePattern: '', messagesPattern: '',
parserConfigurations: [[parserName: 'Pep8', pattern: 'reports/pep8/pep8.report'], [parserName: 'PyLint', pattern: 'reports/**/pylint.report']],
unHealthy: ''
// Publish Quality report
publishHTML([allowMissing: true, alwaysLinkToLastBuild: false, keepAll: true,
reportDir: 'reports/metrics/',
reportFiles: 'pylint/*view*/,pep8/*view*/,python_complexity/*view*/,xsscommitlint/*view*/,xsslint/*view*/,eslint/*view*/',
reportName: 'Quality Report', reportTitles: ''])
} finally {
if (env.ghprbPullId != null) {
// For PR jobs, run the edx-platform-test-notifier for PR reporting
build job: 'edx-platform-test-notifier', parameters: [string(name: 'PR_NUMBER', value: "${ghprbPullId}")], wait: false
} else {
// For master jobs run github-build-status and report to slack when necessary
if (currentBuild.currentResult == "SUCCESS") {
create_deployment = "true"
build_status = "success"
build_description = "Build Passed"
}
else {
create_deployment = "false"
build_status = "failure"
build_description = "Build Failed"
}
commit_sha = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
build job: 'github-build-status', parameters: [
string(name: 'GIT_SHA', value: commit_sha),
string(name: 'GITHUB_ORG', value: 'edx'), string(name: 'GITHUB_REPO', value: 'edx-platform'),
string(name: 'TARGET_URL', value: "${BUILD_URL}"),
string(name: 'DESCRIPTION', value: build_description), string(name: 'CONTEXT', value: 'jenkins/quality'),
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
string(name: 'CREATE_DEPLOYMENT', value: create_deployment), string(name: 'BUILD_STATUS', value: build_status)
],
propagate: false, wait: false
if (currentBuild.currentResult != "SUCCESS"){
slackSend "`${JOB_NAME}` #${BUILD_NUMBER}: ${currentBuild.currentResult} after ${currentBuild.durationString.replace(' and counting', '')}\n${BUILD_URL}"
email_body = "See: <${BUILD_URL}>\n\nChanges:\n"
change_sets = currentBuild.changeSets
for (int j = 0; j < change_sets.size(); j++) {
change_set_items = change_sets[j].items
for (int k = 0; k < change_set_items.length; k++) {
item = change_set_items[k]
email_body = email_body + "\n Commit: ${item.commitId} by ${item.author}: ${item.msg}"
}
}
emailext body: email_body,
subject: "Build failed in Jenkins: ${JOB_NAME} #${BUILD_NUMBER}", to: 'testeng@edx.org'
} else if (currentBuild.currentResult == "SUCCESS" && currentBuild.previousBuild.currentResult != "SUCCESS") {
slackSend "`${JOB_NAME}` #${BUILD_NUMBER}: Back to normal after ${currentBuild.durationString.replace(' and counting', '')}\n${BUILD_URL}"
emailext body: "See <${BUILD_URL}>",
subject: "Jenkins Build is back to normal: ${JOB_NAME} #${BUILD_NUMBER}", to: 'testeng@edx.org'
}
}
}
}
}
}
}