forked from jenkinsci/jenkinsfile-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
124 lines (109 loc) · 3.78 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
/* Only keep the 10 most recent builds. */
properties([[$class: 'BuildDiscarderProperty',
strategy: [$class: 'LogRotator', numToKeepStr: '10']]])
// TODO: Move it to Jenkins Pipeline Library
def branchName = currentBuild.projectName
def buildNumber = currentBuild.number
/* These platforms correspond to labels in ci.jenkins.io, see:
* https://github.com/jenkins-infra/documentation/blob/master/ci.adoc
*/
List platforms = ['linux']
Map branches = [:]
for (int i = 0; i < platforms.size(); ++i) {
String label = platforms[i]
branches[label] = {
node(label) {
timestamps {
ws("platform_${label}_${branchName}_${buildNumber}") {
stage('Checkout') {
checkout scm
}
stage('Build') {
withEnv([
"JAVA_HOME=${tool 'jdk8'}",
"PATH+MVN=${tool 'mvn'}/bin",
'PATH+JDK=$JAVA_HOME/bin',
]) {
timeout(60) {
String command = 'mvn --batch-mode clean package -Dmaven.test.failure.ignore=true -Denvironment=test'
if (isUnix()) {
sh command
} else {
bat command
}
}
}
}
// TODO: Add some tests first
stage('Archive') {
/* Archive the test results */
// junit '**/target/surefire-reports/TEST-*.xml'
//if (label == 'linux') {
// archiveArtifacts artifacts: '**/target/**/*.jar'
// findbugs pattern: '**/target/findbugsXml.xml'
//}
}
}
}
}
}
}
/* Execute our platforms in parallel */
parallel(branches)
stage('Verify demos')
Map demos = [:]
demos['cwp'] = {
node('docker') {
timestamps {
ws("cwp_${branchName}_${buildNumber}") {
checkout scm
stage('CWP') {
dir('demo/cwp') {
sh "make clean buildInDocker run"
}
}
}
}
}
}
demos['databound'] = {
node('docker') {
timestamps {
ws("databound_${branchName}_${buildNumber}") {
checkout scm
stage('Databound') {
dir('demo/databound') {
sh "make clean buildInDocker run"
}
}
}
}
}
}
parallel(demos)
node('docker') {
ws("container_${branchName}_${buildNumber}") {
infra.withDockerCredentials {
def image
def imageName = "${env.DOCKERHUB_ORGANISATION}/jenkinsfile-runner"
def imageTag
stage('Build container') {
timestamps {
def scmVars = checkout scm
def shortCommit = scmVars.GIT_COMMIT
imageTag = branchName.equals("master") ? "latest" : branchName
echo "Creating the container ${imageName}:${imageTag}"
image = docker.build("${imageName}:${imageTag}", '--no-cache --rm .')
}
}
// TODO(oleg-nenashev): Reenable once CI is stable
// if (branchName.startsWith('master')) {
// stage('Publish container') {
// timestamps {
// image.push();
// }
// }
// }
}
}
}