forked from jenkinsci/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
235 lines (213 loc) · 10.5 KB
/
Jenkinsfile
File metadata and controls
235 lines (213 loc) · 10.5 KB
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/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)
// Default environment variable set to allow images publication
def envVars = ['PUBLISH=true']
// List of architectures and corresponding ci.jenkins.io agent labels
def architecturesAndCiJioAgentLabels = [
'amd64': 'docker && amd64',
'arm64': 'arm64docker',
// Using qemu
'ppc64le': 'docker && amd64',
's390x': 'docker && amd64',
]
// Set to true in a replay to simulate a LTS build on ci.jenkins.io
// It will set the environment variables needed for a LTS
// and disable images publication out of caution
def SIMULATE_LTS_BUILD = false
if (SIMULATE_LTS_BUILD) {
envVars = [
'PUBLISH=false',
'TAG_NAME=2.504.3',
// TODO: replace by the first LTS based on 2.534+ when available
'JENKINS_VERSION=2.504.3',
'WAR_SHA=ea8883431b8b5ef6b68fe0e5817c93dc0a11def380054e7de3136486796efeb0',
// Filter out golden file based testing
// To filter out all tests, set BATS_FLAGS="--filter-tags none"
'BATS_FLAGS=--filter-tags "\\!test-type:golden-file"'
]
}
stage('Build') {
def builds = [:]
withEnv(envVars) {
echo '= bake target: linux'
def windowsImageTypes = [
'windowsservercore-ltsc2022'
]
for (anImageType in windowsImageTypes) {
def imageType = anImageType
builds[imageType] = {
def windowsVersionNumber = imageType.split('-')[1].replace('ltsc', '')
def windowsLabel = "windows-${windowsVersionNumber}"
nodeWithTimeout(windowsLabel) {
stage('Checkout') {
checkout scm
}
withEnv(["IMAGE_TYPE=${imageType}"]) {
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 ${imageType}") {
infra.withDockerCredentials {
powershell './make.ps1 build -ImageType ${env:IMAGE_TYPE}'
archiveArtifacts artifacts: 'build-windows_*.yaml', allowEmptyArchive: true
}
}
stage("Test ${imageType}") {
infra.withDockerCredentials {
def windowsTestStatus = powershell(script: './make.ps1 test -ImageType ${env:IMAGE_TYPE}', 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
error('Windows test stage failed.')
}
}
}
// disable until we get the parallel changes merged in
// def branchName = "${env.BRANCH_NAME}"
// if (branchName ==~ 'master'){
// stage('Publish Experimental') {
// infra.withDockerCredentials {
// withEnv(['DOCKERHUB_ORGANISATION=jenkins4eval','DOCKERHUB_REPO=jenkins']) {
// powershell './make.ps1 publish'
// }
// }
// }
// }
} else {
// Only publish when a tag triggered the build & the publication is enabled (ie not simulating a LTS)
if (env.TAG_NAME && (env.PUBLISH == 'true')) {
// Split to ensure any suffix is not taken in account (but allow suffix tags to trigger rebuilds)
String jenkins_version = env.TAG_NAME.split('-')[0]
// Setting WAR_URL to download war from Artifactory instead of mirrors on publication from trusted.ci.jenkins.io
withEnv([
"JENKINS_VERSION=${jenkins_version}",
"WAR_URL=https://repo.jenkins-ci.org/public/org/jenkins-ci/main/jenkins-war/${jenkins_version}/jenkins-war-${jenkins_version}.war"
]) {
stage('Publish') {
infra.withDockerCredentials {
withEnv(['DOCKERHUB_ORGANISATION=jenkins', 'DOCKERHUB_REPO=jenkins']) {
powershell './make.ps1 build -ImageType ${env:IMAGE_TYPE}'
powershell './make.ps1 publish -ImageType ${env:IMAGE_TYPE}'
}
}
}
}
}
}
}
}
}
}
if (!infra.isTrusted()) {
// An up to date list can be obtained with make list-linux
def images = [
'alpine_jdk21',
'alpine_jdk25',
'debian_jdk21',
'debian_jdk25',
'debian-slim_jdk21',
'debian-slim_jdk25',
'rhel_jdk21',
'rhel_jdk25',
]
for (i in images) {
def imageToBuild = i
builds[imageToBuild] = {
nodeWithTimeout(architecturesAndCiJioAgentLabels["amd64"]) {
deleteDir()
stage('Checkout') {
checkout scm
}
stage('Static analysis') {
sh 'make hadolint 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 linux-${imageToBuild}") {
infra.withDockerCredentials {
sh "make build-${imageToBuild}"
archiveArtifacts artifacts: 'target/build-result-metadata_*.json', allowEmptyArchive: true
}
}
stage("Test linux-${imageToBuild}") {
sh 'make prepare-test'
try {
infra.withDockerCredentials {
sh "make test-${imageToBuild}"
}
} catch (err) {
error("${err.toString()}")
} finally {
junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'target/*.xml')
}
}
}
}
}
// Building every other architectures than amd64 on agents with the corresponding labels if available
architecturesAndCiJioAgentLabels.findAll { arch, _ -> arch != 'amd64' }.each { architecture, labels ->
builds[architecture] = {
nodeWithTimeout(labels) {
stage('Checkout') {
deleteDir()
checkout scm
}
// sanity check that proves all images build on declared platforms not already built in other stages
stage("Multi arch build - ${architecture}") {
infra.withDockerCredentials {
sh "make docker-init buildarch-${architecture}"
archiveArtifacts artifacts: 'target/build-result-metadata_*.json', allowEmptyArchive: true
}
}
}
}
}
} else {
// Only publish when a tag triggered the build
if (env.TAG_NAME) {
// Split to ensure any suffix is not taken in account (but allow suffix tags to trigger rebuilds)
String jenkins_version = env.TAG_NAME.split('-')[0]
builds['linux'] = {
// Setting WAR_URL to download war from Artifactory instead of mirrors on publication from trusted.ci.jenkins.io
withEnv([
"JENKINS_VERSION=${jenkins_version}",
"WAR_URL=https://repo.jenkins-ci.org/public/org/jenkins-ci/main/jenkins-war/${jenkins_version}/jenkins-war-${jenkins_version}.war"
]) {
nodeWithTimeout('docker') {
stage('Checkout') {
checkout scm
}
stage('Publish') {
// Publication is enabled by default, disabled when simulating a LTS
if (env.PUBLISH == 'true') {
infra.withDockerCredentials {
sh 'make docker-init'
sh 'make publish'
archiveArtifacts artifacts: 'target/build-result-metadata_*.json', allowEmptyArchive: true
}
}
}
}
}
}
}
}
parallel builds
}
}
void nodeWithTimeout(String label, def body) {
node(label) {
timeout(time: 60, unit: 'MINUTES') {
body.call()
}
}
}