-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJenkinsfile
More file actions
264 lines (252 loc) · 7.61 KB
/
Jenkinsfile
File metadata and controls
264 lines (252 loc) · 7.61 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
library 'magic-butler-catalogue'
def WORKSPACE_PATH = "/tmp/workspace/${env.BUILD_TAG.replace('%2F', '/')}"
def DEFAULT_BRANCH = "master"
def PROJECT_NAME = "vector"
def CURRENT_BRANCH = currentBranch()
def DOCKER_REPO = "docker.io/mezmo"
def TRIGGER_PATTERN = '.*@logdnabot.*'
def BRANCH_BUILD = slugify("${CURRENT_BRANCH}-${BUILD_NUMBER}")
def CREDS = [
string(
credentialsId: 'github-api-token',
variable: 'GITHUB_TOKEN'
),
aws(credentialsId: 'aws',
accessKeyVariable: 'AWS_ACCESS_KEY_ID',
secretKeyVariable: 'AWS_SECRET_ACCESS_KEY'),
]
def NPMRC = [
configFile(fileId: 'npmrc', variable: 'NPM_CONFIG_USERCONFIG')
]
def RELEASE_COMMIT_TITLE = /release: \d{4}-\d{2}-\d{2}, Version \d+\.\d+\.\d+ \[skip ci\] by LogDNA Bot$/
pipeline {
agent {
node {
label "ec2-fleet"
customWorkspace(WORKSPACE_PATH)
}
}
parameters {
string(name: 'SANITY_BUILD', defaultValue: '', description: 'This a scheduled sanity build that skips releasing.')
}
triggers {
parameterizedCron(
// Cron hours are in GMT, so this is roughly 12-3am EST, depending on DST
env.BRANCH_NAME == DEFAULT_BRANCH ? 'H H(5-6) * * * % SANITY_BUILD=true' : ''
)
issueCommentTrigger(TRIGGER_PATTERN)
}
options {
timestamps()
disableConcurrentBuilds()
timeout time: 90, unit: 'MINUTES'
ansiColor 'xterm'
withCredentials(CREDS)
}
environment {
ENVIRONMENT_AUTOBUILD = 'false'
ENVIRONMENT_TTY = 'false'
CI = 'true'
RUST_BACKTRACE = 'full'
RUST_LOG = 'debug'
RUST_TEST_NOCAPTURE = '1'
VECTOR_TARGET = "${BRANCH_BUILD}-target"
VECTOR_CARGO_CACHE = "${BRANCH_BUILD}-cargo"
VECTOR_RUSTUP_CACHE = "${BRANCH_BUILD}-rustup"
TOP_COMMIT = sh(
script: 'git log --pretty="format:%s by %cn" HEAD | head -1',
returnStdout: true
).trim()
}
stages {
stage('Validate PR Author') {
when {
expression { env.CHANGE_FORK }
not {
triggeredBy 'issueCommentCause'
}
}
steps {
error("A maintainer needs to approve this PR for CI by commenting")
}
}
stage('Release Tool') {
steps {
sh 'make release-tool'
}
}
stage('Needs Testing?') {
// Do not run the stages on a release commit, unless it's for a sanity build.
when {
anyOf {
expression { !(env.TOP_COMMIT ==~ RELEASE_COMMIT_TITLE) }
environment name: 'SANITY_BUILD', value: 'true'
}
}
stages {
stage('Lint and test release'){
when {
allOf {
expression { !(env.TOP_COMMIT ==~ /^Merge remote-tracking branch.*$/) }
expression { !(env.TOP_COMMIT ==~ /^Merge upstream.*$/) }
expression { !(env.TOP_COMMIT ==~ /^Merge tag.*$/) }
expression { !(env.TOP_COMMIT ==~ /^.*\[skip lint\].*$/) }
}
}
tools {
nodejs 'NodeJS 20'
}
environment {
GIT_BRANCH = "${CURRENT_BRANCH}"
// This is not populated on PR builds and is needed for the release dry runs
BRANCH_NAME = "${CURRENT_BRANCH}"
CHANGE_ID = ""
}
steps {
script {
configFileProvider(NPMRC) {
sh 'npm ci'
sh 'npm run release:dry'
}
}
sh './release-tool lint'
sh './release-tool test'
}
}
stage('Checks'){
steps {
// NOTE(pciampini): speed up the checks by disabling auto-builds
sh """
make check-scripts ENVIRONMENT=true ENVIRONMENT_AUTOBUILD=false
make check-fmt ENVIRONMENT=true ENVIRONMENT_AUTOBUILD=false
make check-clippy ENVIRONMENT=true ENVIRONMENT_AUTOBUILD=false
"""
}
}
stage('Unit test'){
steps {
sh """
make test ENVIRONMENT=true ENVIRONMENT_AUTOBUILD=false ENVIRONMENT_AUTOPULL=false
"""
}
}
stage('image test') {
when {
allOf{
changeRequest() // Only do this during PRs because it can take 30 minutes
changeset "distribution/docker/mezmo/Dockerfile"
}
}
steps {
script {
def semver = npm.semver()
def pkg_version = "${semver.version}+${BRANCH_BUILD}"
buildx.build(
project: PROJECT_NAME
, push: false
, tags: [BRANCH_BUILD]
, dockerfile: "distribution/docker/mezmo/Dockerfile"
, args: [RELEASE_VERSION: pkg_version]
, docker_repo: DOCKER_REPO
)
}
}
}
stage('Feature build and publish') {
when {
expression {
CURRENT_BRANCH ==~ /feature\/LOG-\d+/
}
}
steps {
script {
def tag = slugify("${CURRENT_BRANCH}-${BUILD_NUMBER}")
def semver = npm.semver()
def pkg_version = "${semver.version}+${tag}"
buildx.build(
project: PROJECT_NAME
, push: true
, tags: [tag]
, dockerfile: "distribution/docker/mezmo/Dockerfile"
, args: [RELEASE_VERSION: pkg_version]
, docker_repo: DOCKER_REPO
)
}
sh './release-tool clean'
sh "./release-tool build APP_VERSION='" + slugify("${CURRENT_BRANCH}-${BUILD_NUMBER}") + "'"
sh "./release-tool publish RELEASE_VERSION='" + slugify("${CURRENT_BRANCH}-${BUILD_NUMBER}") + "'"
archiveArtifacts artifacts: 'output/'
}
}
stage('Release Commit') {
when {
branch DEFAULT_BRANCH
not {
environment name: 'SANITY_BUILD', value: 'true'
}
}
tools {
nodejs 'NodeJS 20'
}
steps {
script {
configFileProvider(NPMRC) {
sh 'npm ci'
sh 'npm run release'
}
}
}
}
}
}
stage('Publish') {
when {
allOf {
branch DEFAULT_BRANCH
expression { env.TOP_COMMIT ==~ RELEASE_COMMIT_TITLE }
not {
environment name: 'SANITY_BUILD', value: 'true'
}
}
}
steps {
script {
def tag = sh (
script: "./release-tool debug-RELEASE_VERSION",
returnStdout: true
).split(' = ')[1].trim()
buildx.build(
project: PROJECT_NAME
, push: true
, tags: [tag]
, dockerfile: "distribution/docker/mezmo/Dockerfile"
, args: [RELEASE_VERSION: tag]
, docker_repo: DOCKER_REPO
)
}
sh './release-tool clean'
sh './release-tool build'
sh './release-tool publish'
}
}
}
post {
always {
// Clear disk space by removing the test container and all of its volumes.
// The container and volumes are unique to the current build, so there should be no "in use" errors.
sh 'make environment-clean'
script {
if (env.SANITY_BUILD == 'true') {
notifySlack(
currentBuild.currentResult,
[
channel: '#pipeline-bots',
tokenCredentialId: 'qa-slack-token'
],
"`${PROJECT_NAME}` sanity build took ${currentBuild.durationString.replaceFirst(' and counting', '')}."
)
}
}
}
}
}