-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile.nightly
180 lines (176 loc) · 7.12 KB
/
Jenkinsfile.nightly
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
def scmVars
mmMessage = ''
def prepare_post(def scmResult) {
switch(currentBuild.currentResult) {
case 'SUCCESS':
env.mm_color = 'good'
break
case 'UNSTABLE':
env.mm_color = '#ebc934'
break
default:
env.mm_color = 'danger'
break
}
def changeLogSets = currentBuild.changeSets
def changeMessage = ""
for (int i = 0; i < changeLogSets.size(); i++) {
def entries = changeLogSets[i].items
for (int j = 0; j < entries.length; j++) {
def entry = entries[j]
changeMessage +=" * ${entry.commitId} by ${entry.author} on ${new Date(entry.timestamp)}: ${entry.msg}\n"
}
}
mmMessage = """Build ${currentBuild.id} of **${java.net.URLDecoder.decode env.JOB_NAME, 'UTF-8'}** finished with **${currentBuild.currentResult}**.
#### Links
* <${env.BUILD_URL}display/redirect|Open Jenkins log>
* <${env.RUN_CHANGES_DISPLAY_URL}|Open changes in Jenkins>
* <${scmResult.GIT_URL}|Open project in GitHub>
#### Changes
${changeMessage}
"""
}
// TODO
// * Generate badge for test failure and add it to the readme.md
// https://github.com/jenkinsci/embeddable-build-status-plugin#embeddable-build-status-plugin is already installed
// Either generate Sonar badges as well (can I access Sonar API from pipeline? Probably...), or make Sonar project public
// * https://github.com/jenkinsci/git-forensics-plugin and https://github.com/jenkinsci/forensics-api-plugin allow the discovery of reference builds
// publishCoverage adapters: [jacocoAdapter(mergeToOneReport: true, path: '')], globalThresholds: [[thresholdTarget: 'Aggregated Report']], sourceFileResolver: sourceFiles('NEVER_STORE')
// https://www.jenkins.io/blog/2019/07/21/Jenkins-code-coverage-diff-for-pull-request/
// * TODO: It might be necessary to change the maven build to use cobertura instead of jacoco to support delta for test cases
// * Exclude certain classes from coverage (i.e., UltimateTest, java.bdd, ...)
// * Access test results for dependent nightly release and mattermost messages https://stackoverflow.com/questions/39920437/how-to-access-junit-test-counts-in-jenkins-pipeline-project
pipeline {
agent { label 'linux' && 'java' }
triggers {
cron('@midnight')
}
options {
skipDefaultCheckout()
timeout(time: 10, unit: 'HOURS')
}
environment {
PATH = "${env.WORKSPACE}/releaseScripts/default/adds:${env.PATH}"
}
stages {
stage('Checkout') {
steps {
script {
scmVars = checkout scm
echo "Building for ${currentBuild.changeSets.size()} changes"
}
sh 'git clean -f -x -d'
}
}
stage('Check environment') {
when {
anyOf {
expression { return !currentBuild.changeSets.isEmpty() }
triggeredBy cause: 'UserIdCause'
}
}
steps {
sh(label: 'check solvers', script: 'releaseScripts/default/check_solvers.sh')
}
}
// stage('Collect repository statistics') {
// //TODO: Runs really long, perhaps it should be a separate job or
// when {
// allOf {
// //branch 'dev'
// expression { return !currentBuild.changeSets.isEmpty() }
// }
// }
// steps {
// catchError(buildResult: null, catchInterruptions: false) {
// mineRepository()
// }
// }
// }
stage('Collect reference build') {
when {
anyOf {
expression { return !currentBuild.changeSets.isEmpty() }
triggeredBy cause: 'UserIdCause'
}
}
steps {
catchError(buildResult: null, catchInterruptions: false) {
discoverGitReferenceBuild(latestBuildIfNotFound: true, targetBranch: 'dev')
}
}
}
stage('Build and run nightly tests') {
when {
anyOf {
expression { return !currentBuild.changeSets.isEmpty() }
triggeredBy cause: 'UserIdCause'
}
}
steps {
withMaven(mavenOpts: '-Xmx4g -Xss4m -ea', options: [artifactsPublisher(disabled: true), junitPublisher(healthScaleFactor: 1.0, keepLongStdio: true, skipPublishingChecks: false)]) {
//TODO Remove using icfgtransformer tests as test of the jenkinsfile (was: -Dtest=QuadraticMatrixTest )
sh 'cd trunk/source/BA_MavenParentUltimate && mvn -T 1C clean install -Pcoverage -Dmaven.test.failure.ignore=true'
}
}
}
// stage('Report'){
// steps {
// junit keepLongStdio: true, testResults: 'prototype/test_results.xml'
// cobertura coberturaReportFile: 'prototype/cov-cobertura.xml'
// catchError(buildResult: 'SUCCESS', catchInterruptions: false) {
// //do not let coverage result errors fail the build
// publishCoverage adapters: [coberturaAdapter('prototype/cov-cobertura.xml')], calculateDiffForChangeRequests: true, sourceFileResolver: sourceFiles('NEVER_STORE')
// }
// }
// }
stage('Run Sonar') {
when {
allOf {
expression { return currentBuild.result == "SUCCESS" || currentBuild.result == "UNSTABLE" }
branch 'dev'
anyOf {
expression { return !currentBuild.changeSets.isEmpty() }
triggeredBy cause: 'UserIdCause'
}
}
}
steps {
withCredentials([string(credentialsId: "SonarTokenJenkinsPipeline", variable: 'SONAR_TOKEN')]) {
withMaven(mavenOpts: '-Xmx4g -Xss4m', options: [jacocoPublisher()], publisherStrategy: 'EXPLICIT') {
sh 'cd trunk/source/BA_MavenParentUltimate && mvn sonar:sonar -Pcoverage -Dsonar.host.url=https://sonar.sopranium.de -Dsonar.login=$SONAR_TOKEN'
}
}
}
}
stage('Deploy nightly build') {
when {
allOf {
branch 'dev'
expression { return !currentBuild.changeSets.isEmpty() }
expression { return currentBuild.result == "SUCCESS" || currentBuild.result == "UNSTABLE" }
}
}
steps {
withMaven(mavenOpts: '-Xmx4g -Xss4m', publisherStrategy: 'EXPLICIT') {
sh 'cd releaseScripts/default && ./makeFresh.sh'
}
sshagent (credentials: ['jenkins-deploy']) {
sh (label: 'deploy nightly to struebli', script: 'releaseScripts/default/deploy_nightly_to_struebli.sh')
}
}
}
}
post {
unsuccessful {
script { prepare_post(scmVars) }
emailext(body: '$DEFAULT_CONTENT', mimeType: 'text/plain', recipientProviders: [culprits(), developers(), requestor()], replyTo: '[email protected]', subject: '$DEFAULT_SUBJECT')
mattermostSend(color: "${env.mm_color}", message: "${mmMessage}", text: '', channel: '#ultimate', icon: "https://jenkins.sopranium.de/static/0e41ff2a/images/jenkins-header-logo-v2.svg")
}
fixed {
script { prepare_post(scmVars) }
emailext(body: '$DEFAULT_CONTENT', mimeType: 'text/plain', recipientProviders: [culprits(), developers(), requestor()], replyTo: '[email protected]', subject: '$DEFAULT_SUBJECT')
mattermostSend(color: "${env.mm_color}", message: "${mmMessage}", text: '', channel: '#ultimate', icon: "https://jenkins.sopranium.de/static/0e41ff2a/images/jenkins-header-logo-v2.svg")
}
}
}