-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathJenkinsfile
More file actions
241 lines (228 loc) · 9.89 KB
/
Jenkinsfile
File metadata and controls
241 lines (228 loc) · 9.89 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
236
237
238
239
240
241
pipeline {
agent { label 'CONTAINERS' }
environment {
REPOS = "core enterprise nova masterfiles northerntechhq/nt-docs"
PR_BASE = getPR_BASE()
DOCS_BRANCH = getDOCS_BRANCH()
PACKAGE_JOB = "cf-remote"
PACKAGE_UPLOAD_DIRECTORY = "n/a"
PACKAGE_BUILD = "n/a"
}
parameters {
string(name: "CORE_REV", defaultValue: '', description: 'used for changelog, examples. Use NUMBER or "pull/NUMBER/merge" for pull request (it\'s merged version, THIS DOESN\'T MERGE THE PR) or "pull/NUMBER/head" to build the docs with the non-merged code. Special syntax \'tag:SOME_TAG\' can be used to use a tag as a revision.')
string(name: "NOVA_REV", defaultValue: '', description: 'used for changelog. Use NUMBER or "pull/NUMBER/merge" for pull request (it\'s merged version, THIS DOESN\'T MERGE THE PR) or "pull/NUMBER/head" to build the docs with the non-merged code. Special syntax \'tag:SOME_TAG\' can be used to use a tag as a revision.')
string(name: "ENTERPRISE_REV", defaultValue: '', description: 'used for changelog. Use NUMBER or "pull/NUMBER/merge" for pull request (it\'s merged version, THIS DOESN\'T MERGE THE PR) or "pull/NUMBER/head" to build the docs with the non-merged code. Special syntax \'tag:SOME_TAG\' can be used to use a tag as a revision.')
string(name: "MASTERFILES_REV", defaultValue: '', description: 'used to document masterfiles. Use NUMBER or "pull/NUMBER/merge" for pull request (it\'s merged version, THIS DOESN\'T MERGE THE PR) or "pull/NUMBER/head" to build the docs with the non-merged code. Special syntax \'tag:SOME_TAG\' can be used to use a tag as a revision.')
string(name: "DOCS_REV", defaultValue: '', description: 'Use NUMBER or "pull/NUMBER/merge" for pull request (it\'s merged version, THIS DOESN\'T MERGE THE PR) or "pull/NUMBER/head" to build the docs with the non-merged code. Special syntax \'tag:SOME_TAG\' can be used to use a tag as a revision.')
string(name: "NT_DOCS_REV", defaultValue: '', description: 'Use NUMBER or "pull/NUMBER/merge" for pull request (it\'s merged version, THIS DOESN\'T MERGE THE PR) or "pull/NUMBER/head" to build the docs with the non-merged code. Special syntax \'tag:SOME_TAG\' can be used to use a tag as a revision.')
string(name: "DOCS_BRANCH", defaultValue: '', description: 'Where to upload artifacts - to http://buildcache.cloud.cfengine.com/packages/build-documentation-$DOCS_BRANCH/ and https://docs.cfengine.com/docs/$DOCS_BRANCH/')
string(name: "PACKAGE_JOB", defaultValue: 'cf-remote', description: 'where to get CFEngine HUB package from, either a dir at http://buildcache.cloud.cfengine.com/packages like testing-pr or a keyword cf-remote to use cf-remote download')
string(name: "USE_NIGHTLIES_FOR", defaultValue: '', description: 'branch whose nightlies to use (master, 3.18.x, etc) - will be one of http://buildcache.cloud.cfengine.com/packages/testing-pr/jenkins-$USE_NIGHTLIES_FOR-nightly-pipeline-$NUMBER/')
}
triggers {
// Run nightly at 2 AM to trigger builds for master, 3.27, 3.24, and lts
cron('H 2 * * *')
}
options {
checkoutToSubdirectory('documentation')
}
stages {
stage('Trigger Nightly Builds') {
when {
triggeredBy 'TimerTrigger'
}
steps {
script {
echo "Triggered by cron - launching builds for master, 3.27, 3.24, and lts"
// Build master
build job: env.JOB_NAME, parameters: [
string(name: 'CORE_REV', value: 'master'),
string(name: 'ENTERPRISE_REV', value: 'master'),
string(name: 'NOVA_REV', value: 'master'),
string(name: 'MASTERFILES_REV', value: 'master'),
string(name: 'DOCS_REV', value: 'master'),
string(name: 'NT_DOCS_REV', value: 'main'),
string(name: 'DOCS_BRANCH', value: 'master'),
string(name: 'PACKAGE_JOB', value: 'cf-remote'),
string(name: 'USE_NIGHTLIES_FOR', value: 'master')
], wait: false
// Build 3.27
build job: env.JOB_NAME, parameters: [
string(name: 'CORE_REV', value: '3.27.x'),
string(name: 'ENTERPRISE_REV', value: '3.27.x'),
string(name: 'NOVA_REV', value: '3.27.x'),
string(name: 'MASTERFILES_REV', value: '3.27.x'),
string(name: 'DOCS_REV', value: '3.27'),
string(name: 'NT_DOCS_REV', value: 'main'),
string(name: 'DOCS_BRANCH', value: '3.27'),
string(name: 'PACKAGE_JOB', value: 'cf-remote'),
string(name: 'USE_NIGHTLIES_FOR', value: '3.27.x')
], wait: false
// Build 3.24
build job: env.JOB_NAME, parameters: [
string(name: 'CORE_REV', value: '3.24.x'),
string(name: 'ENTERPRISE_REV', value: '3.24.x'),
string(name: 'NOVA_REV', value: '3.24.x'),
string(name: 'MASTERFILES_REV', value: '3.24.x'),
string(name: 'DOCS_REV', value: '3.24'),
string(name: 'NT_DOCS_REV', value: 'main'),
string(name: 'DOCS_BRANCH', value: '3.24'),
string(name: 'PACKAGE_JOB', value: 'cf-remote'),
string(name: 'USE_NIGHTLIES_FOR', value: '3.24.x')
], wait: false
// Build lts (3.27.x code deployed to lts location)
build job: env.JOB_NAME, parameters: [
string(name: 'CORE_REV', value: '3.27.x'),
string(name: 'ENTERPRISE_REV', value: '3.27.x'),
string(name: 'NOVA_REV', value: '3.27.x'),
string(name: 'MASTERFILES_REV', value: '3.27.x'),
string(name: 'DOCS_REV', value: '3.27'),
string(name: 'NT_DOCS_REV', value: 'main'),
string(name: 'DOCS_BRANCH', value: 'lts'),
string(name: 'PACKAGE_JOB', value: 'cf-remote'),
string(name: 'USE_NIGHTLIES_FOR', value: '3.27.x')
], wait: false
echo "All nightly builds triggered successfully"
}
}
}
stage('Environment check') {
when {
not {
triggeredBy 'TimerTrigger'
}
}
steps {
sh 'env'
sh 'whoami; pwd; ls'
sh 'uname -a; cat /etc/os-release'
}
}
// we clean FIRST and NOT at the end of the job so that we can replay various stages and have the build result from previous runs
stage('Clean workspace') {
when {
not {
triggeredBy 'TimerTrigger'
}
}
steps {
sh 'for r in $REPOS; do rm -rf "$(basename "$r")"; done'
}
}
stage('Checkout repositories'){
when {
not {
triggeredBy 'TimerTrigger'
}
}
steps {
script {
if (env.CHANGE_ID) {
sh "echo \"${pullRequest.title}\" > pull-request-title"
sh "echo \"${pullRequest.body}\" > pull-request-body"
}
}
sh "curl -O https://raw.githubusercontent.com/cfengine/buildscripts/refs/heads/master/ci/create-revisions-file.sh"
sh "chmod u+x ./create-revisions-file.sh"
sh "./create-revisions-file.sh"
sh "cat revisions"
sh "curl -O https://gitlab.com/Northern.tech/OpenSource/GODS/-/raw/master/parallel_git_rev_fetch.sh"
sh "chmod u+x ./parallel_git_rev_fetch.sh"
withCredentials([sshUserPrivateKey(credentialsId:"autobuild", keyFileVariable: "key")]) {
sh 'export GIT_SSH_COMMAND="ssh -i $key"; ./parallel_git_rev_fetch.sh revisions'
}
}
}
stage('Build documentation') {
when {
not {
triggeredBy 'TimerTrigger'
}
}
steps {
sh 'bash -x documentation/generator/build/run.sh'
}
}
stage('Publish to buildcache') {
when {
not {
triggeredBy 'TimerTrigger'
}
}
steps {
sshPublisher(
// we must use alwaysPublishFromMaster: true because our CONTAINERS build hosts are not in the private network which has access to buildcache.cloud.cfengine.com
alwaysPublishFromMaster: true,
publishers: [
sshPublisherDesc(
configName: 'buildcache.cloud.cfengine.com',
transfers: [
sshTransfer(
cleanRemote: false,
excludes: '',
execCommand: '''
#!/usr/bin/env bash
set -x
WRKDIR="$(pwd)"
export WRKDIR
mkdir -p upload
mkdir -p output
# find two tarballs
archive="$(find upload -name "cfengine-documentation-*.tar.gz")"
tarball=$(findfind upload -name packed-for-shipping.tar.gz)
echo "TARBALL: $tarball"
echo "ARCHIVE: $archive"
# unpack $tarball
( # shubshell to change directories
cd "$(dirname "$tarball")" || exit
tar zxvf packed-for-shipping.tar.gz
rm packed-for-shipping.tar.gz
# move $archive to the _site
mv "$WRKDIR/$archive" _site
ls -la
)
ls -la upload
# note: this triggers systemd job to AV-scan new files
# and move them to proper places
mv upload/* output
''',
execTimeout: 120000,
flatten: false,
makeEmptyDirs: false,
noDefaultExcludes: false,
patternSeparator: '[, ]+',
remoteDirectory: getRemoteDirectory(),
remoteDirectorySDF: false,
removePrefix: '',
sourceFiles: 'output/'
) // sshTransfer
], // transfers
usePromotionTimestamp: false,
useWorkspaceInPromotion: false,
verbose: false
) // sshPublisherDesc
] // publishers
) // sshPublisher
} // steps
} // stage('Publish to buildcache')
} // stages
}
def getDOCS_BRANCH() {
if (env.DOCS_BRANCH) {
return env.DOCS_BRANCH
} else if (env.CHANGE_ID) {
return "${env.CHANGE_TARGET}"
} else {
return "${env.BRANCH_NAME}"
}
}
def getPR_BASE() {
if (env.CHANGE_ID) {
return "${pullRequest.base}"
} else {
return ""
}
}
def getRemoteDirectory() {
return "upload/${env.BUILD_TAG}/build-documentation-${env.DOCS_BRANCH}/${env.BUILD_TAG}/"
}