forked from jenkinsci/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
159 lines (137 loc) · 5.56 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
#!/usr/bin/env groovy
def listOfProperties = []
listOfProperties << buildDiscarder(logRotator(numToKeepStr: '50', artifactNumToKeepStr: '5'))
// Only master branch will run on a timer basis
if (env.BRANCH_NAME.trim() == 'master') {
listOfProperties << pipelineTriggers([cron('''H H/6 * * 0-2,4-6
H 6,21 * * 3''')])
}
properties(listOfProperties)
stage('Build') {
def builds = [:]
builds['windows'] = {
nodeWithTimeout('windock') {
stage('Checkout') {
checkout scm
}
if (!infra.isTrusted()) {
/* Outside of the trusted.ci environment, we're building and testing
* the Dockerfile in this repository, but not publishing to docker hub
*/
stage('Build') {
infra.withDockerCredentials {
powershell './make.ps1'
}
}
stage('Test') {
infra.withDockerCredentials {
def windowsTestStatus = powershell(script: './make.ps1 test', returnStatus: true)
junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'target/**/junit-results.xml')
if (windowsTestStatus > 0) {
// If something bad happened let's clean up the docker images
powershell(script: '& docker system prune --force --all', returnStatus: true)
error('Windows test stage failed.')
}
}
}
def branchName = "${env.BRANCH_NAME}"
if (branchName ==~ 'master'){
stage('Publish Experimental') {
infra.withDockerCredentials {
withEnv(['DOCKERHUB_ORGANISATION=jenkins4eval','DOCKERHUB_REPO=jenkins']) {
powershell './make.ps1 publish'
}
}
}
}
// Let's always clean up the docker images at the very end
powershell(script: '& docker system prune --force --all', returnStatus: true)
} else {
/* In our trusted.ci environment we only want to be publishing our
* containers from artifacts
*/
stage('Publish') {
infra.withDockerCredentials {
withEnv(['DOCKERHUB_ORGANISATION=jenkins','DOCKERHUB_REPO=jenkins']) {
powershell './make.ps1 publish'
}
}
}
}
}
}
builds['linux'] = {
nodeWithTimeout('docker') {
deleteDir()
stage('Checkout') {
checkout scm
}
if (!infra.isTrusted()) {
stage('shellcheck') {
// run shellcheck ignoring error SC1091
// Not following: /usr/local/bin/jenkins-support was not specified as input
sh 'make shellcheck'
}
/* Outside of the trusted.ci environment, we're building and testing
* the Dockerfile in this repository, but not publishing to docker hub
*/
stage('Build') {
infra.withDockerCredentials {
sh 'make build'
}
}
stage('Prepare Test') {
sh "make prepare-test"
}
def labels = ['debian', 'slim', 'alpine', 'jdk11', 'centos', 'centos7']
def builders = [:]
for (x in labels) {
def label = x
// Create a map to pass in to the 'parallel' step so we can fire all the builds at once
builders[label] = {
stage("Test ${label}") {
try {
infra.withDockerCredentials {
sh "make test-$label"
}
} catch(err) {
error("${err.toString()}")
} finally {
junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'target/*.xml')
}
}
}
}
parallel builders
def branchName = "${env.BRANCH_NAME}"
if (branchName ==~ 'master'){
stage('Publish Experimental') {
infra.withDockerCredentials {
sh 'make publish-tags'
sh 'make publish-manifests'
}
}
}
// Let's always clean up the docker images at the very end
sh(script: 'docker system prune --force --all', returnStatus: true)
} else {
/* In our trusted.ci environment we only want to be publishing our
* containers from artifacts
*/
stage('Publish') {
infra.withDockerCredentials {
sh 'make publish'
}
}
}
}
}
parallel builds
}
void nodeWithTimeout(String label, def body) {
node(label) {
timeout(time: 60, unit: 'MINUTES') {
body.call()
}
}
}