-
-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathJenkinsfile
More file actions
167 lines (153 loc) · 6.83 KB
/
Jenkinsfile
File metadata and controls
167 lines (153 loc) · 6.83 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
final String cronExpr = env.BRANCH_IS_PRIMARY ? '@daily' : ''
properties([
buildDiscarder(logRotator(numToKeepStr: '10')),
disableConcurrentBuilds(abortPrevious: true),
pipelineTriggers([cron(cronExpr)]),
])
def agentSelector(String imageType, retryCounter) {
def platform
switch (imageType) {
// nanoserver-ltsc2019 and windowservercore-ltsc2019
case ~/.*2019/:
platform = 'windows-2019'
break
// nanoserver-ltsc2022 and windowservercore-ltsc2022
case ~/.*2022/:
platform = 'windows-2022'
break
// nanoserver-ltsc2025 and windowservercore-ltsc2025
case ~/.*2025/:
platform = 'windows-2025'
break
// Linux
default:
// Need Docker and a LOT of memory for faster builds (due to multi archs)
platform = 'docker-highmem'
break
}
// Defined in https://github.com/jenkins-infra/pipeline-library/blob/master/vars/infra.groovy
return infra.getBuildAgentLabel([
useContainerAgent: false,
platform: platform,
spotRetryCounter: retryCounter
])
}
// Defaul values
def tagWithOneDashExist = false
def remotingVersion = '3355.v388858a_47b_33'
def buildNumber = env.BUILD_NUMBER
// Values on tag containing the remoting version and build number
if (env.TAG_NAME) {
def tagItems = env.TAG_NAME.split('-')
if (tagItems.length == 2) {
tagWithOneDashExist = true
remotingVersion = tagItems[0]
buildNumber = tagItems[1]
}
}
// Specify parallel stages
// Linux: bake group(s) or target(s), see 'make list' or 'make listgroup-linux' output
// Windows: flavor and version to build
def parallelStages = [failFast: false]
[
'alpine',
'debian',
'rhel_ubi9',
'nanoserver-ltsc2019',
'nanoserver-ltsc2022',
'windowsservercore-ltsc2019',
'windowsservercore-ltsc2022'
].each { imageType ->
parallelStages[imageType] = {
withEnv([
"ON_TAG=${tagWithOneDashExist}",
"REMOTING_VERSION=${remotingVersion}",
"BUILD_NUMBER=${buildNumber}",
"IMAGE_TYPE=${imageType}",
"REGISTRY_ORG=${infra.isTrusted() ? 'jenkins' : 'jenkins4eval'}"
]) {
int retryCounter = 0
retry(count: 2, conditions: [agent(), nonresumable()]) {
// Use local variable to manage concurrency and increment BEFORE spinning up any agent
final String resolvedAgentLabel = agentSelector(imageType, retryCounter)
retryCounter++
node(resolvedAgentLabel) {
timeout(time: 60, unit: 'MINUTES') {
checkout scm
stage("Prepare Docker on ${resolvedAgentLabel}") {
if (isUnix()) {
sh 'make docker-init'
} else {
powershell './make.ps1 docker-init'
archiveArtifacts artifacts: 'build-windows_*.yaml', allowEmptyArchive: true
}
}
if (isUnix()) {
stage('Checks') {
sh 'make hadolint'
sh 'make shellcheck'
}
}
// No single arch build or test on trusted.ci.jenkins.io
if (!infra.isTrusted()) {
// Build current arch for Linux images
stage('Build current arch') {
if (isUnix()) {
sh 'make "build-${IMAGE_TYPE}"'
} else {
// No multiarch Windows images
powershell './make.ps1 build'
}
}
stage('Test') {
if (isUnix()) {
sh 'make "test-${IMAGE_TYPE}"'
} else {
powershell './make.ps1 test'
}
junit(allowEmptyResults: true, keepLongStdio: true, testResults: 'target/**/junit-results*.xml')
}
archiveArtifacts artifacts: 'target/build-result-metadata_*.json', allowEmptyArchive: true
}
// If the tests are passing for Linux AMD64 or if we're on trusted.ci.jenkins.io
// then we build all the CPU architectures
stage('Build multiarch') {
if (isUnix()) {
sh 'make "multiarchbuild-${IMAGE_TYPE}"'
} else {
// No multiarch images for Windows, (re)building them here on both controllers
powershell './make.ps1 build'
}
archiveArtifacts artifacts: 'target/build-result-metadata_*.json', allowEmptyArchive: true
}
// trusted.ci.jenkins.io builds (e.g. publication to DockerHub)
if (infra.isTrusted()) {
stage('Deploy to DockerHub') {
if (!tagWithOneDashExist) {
error("The deployment to Docker Hub failed because the tag doesn't contain any '-'.")
}
// This function is defined in the jenkins-infra/pipeline-library
infra.withDockerCredentials {
if (isUnix()) {
if (imageType != 'linux') {
sh 'make "publish-${IMAGE_TYPE}"'
} else {
// Batch Linux images publication by distribution to avoid 429 rate limit errors from Docker Hub
sh 'make listgroup-linux | xargs -I {} make "publish-{}"'
}
} else {
powershell './make.ps1 publish'
}
}
archiveArtifacts artifacts: 'target/build-result-metadata_*.json', allowEmptyArchive: true
}
}
}
}
}
}
}
}
// Execute parallel stages
parallel parallelStages
// // vim: ft=groovy