-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
211 lines (207 loc) · 6.5 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
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
@Library('socrata-pipeline-library')
import com.socrata.ReleaseMetadataService
def rmsSupportedEnvironment = com.socrata.ReleaseMetadataService.SupportedEnvironment
String service = 'query-coordinator'
String project_wd = service
boolean isPr = env.CHANGE_ID != null
boolean isHotfix = isHotfixBranch(env.BRANCH_NAME)
boolean skip = false
boolean lastStage
// Utility Libraries
def sbtbuild = new com.socrata.SBTBuild(steps, service, project_wd)
def dockerize = new com.socrata.Dockerize(steps, service, BUILD_NUMBER)
def releaseTag = new com.socrata.ReleaseTag(steps, service)
pipeline {
options {
ansiColor('xterm')
buildDiscarder(logRotator(numToKeepStr: '50'))
disableConcurrentBuilds(abortPrevious: true)
timeout(time: 20, unit: 'MINUTES')
}
parameters {
string(name: 'AGENT', defaultValue: 'build-worker-pg13', description: 'Which build agent to use?')
string(name: 'BRANCH_SPECIFIER', defaultValue: 'origin/main', description: 'Use this branch for building the artifact.')
booleanParam(name: 'RELEASE_BUILD', defaultValue: false, description: 'Are we building a release candidate?')
booleanParam(name: 'RELEASE_DRY_RUN', defaultValue: false, description: 'To test out the release build .')
string(name: 'RELEASE_NAME', description: 'For release builds, the release name which is used in the git tag and the build id.')
}
agent {
label params.AGENT
}
environment {
WEBHOOK_ID = 'WEBHOOK_IQ'
}
stages {
stage('Hotfix') {
when {
expression { isHotfix }
}
steps {
script {
lastStage = env.STAGE_NAME
if (releaseTag.noCommitsOnHotfixBranch(env.BRANCH_NAME)) {
skip = true
echo "SKIP: Skipping the rest of the build because there are no commits on the hotfix branch yet"
} else {
env.CURRENT_RELEASE_NAME = releaseTag.getReleaseName(env.BRANCH_NAME)
env.HOTFIX_NAME = releaseTag.getHotfixName(env.CURRENT_RELEASE_NAME)
}
}
}
}
stage('Build') {
when {
not { expression { skip } }
}
steps {
script {
lastStage = env.STAGE_NAME
sbtbuild.setScalaVersion("2.12")
sbtbuild.setSubprojectName("queryCoordinator")
sbtbuild.setSrcJar("query-coordinator/target/query-coordinator-assembly.jar")
sbtbuild.build()
}
}
}
stage('Docker Build') {
when {
allOf {
not { expression { isPr } }
not { expression { skip } }
}
}
steps {
script {
lastStage = env.STAGE_NAME
if (params.RELEASE_BUILD || isHotfix) {
env.VERSION = (isHotfix) ? env.HOTFIX_NAME : params.RELEASE_NAME
env.DOCKER_TAG = dockerize.dockerBuildWithSpecificTag(
tag: env.VERSION,
path: sbtbuild.getDockerPath(),
artifacts: [sbtbuild.getDockerArtifact()]
)
} else {
env.DOCKER_TAG = dockerize.dockerBuildWithDefaultTag(
version: 'STAGING',
sha: env.GIT_COMMIT,
path: sbtbuild.getDockerPath(),
artifacts: [sbtbuild.getDockerArtifact()]
)
}
}
}
post {
success {
script {
if (isHotfix) {
env.GIT_TAG = releaseTag.create(env.HOTFIX_NAME)
} else if (params.RELEASE_BUILD) {
env.GIT_TAG = releaseTag.getFormattedTag(params.RELEASE_NAME)
if (releaseTag.doesReleaseTagExist(params.RELEASE_NAME)) {
echo "REBUILD: Tag ${env.GIT_TAG} already exists"
return
}
if (params.RELEASE_DRY_RUN) {
echo "DRY RUN: Would have created ${env.GIT_TAG} and pushed it to the repo"
currentBuild.description = "${service}:${params.RELEASE_NAME} - DRY RUN"
return
}
releaseTag.create(params.RELEASE_NAME)
}
}
}
}
}
stage('Publish') {
when {
allOf {
not { expression { isPr } }
not { expression { skip } }
not { expression { return params.RELEASE_BUILD && params.RELEASE_DRY_RUN } }
}
}
steps {
script {
lastStage = env.STAGE_NAME
if (isHotfix || params.RELEASE_BUILD) {
env.BUILD_ID = dockerize.publish(sourceTag: env.DOCKER_TAG)
} else {
env.BUILD_ID = dockerize.publish(
sourceTag: env.DOCKER_TAG,
environments: ['internal']
)
}
currentBuild.description = env.BUILD_ID
}
}
post {
success {
script {
if (isHotfix || params.RELEASE_BUILD) {
env.PURPOSE = (isHotfix) ? 'hotfix' : 'initial'
env.RELEASE_ID = (isHotfix) ? env.CURRENT_RELEASE_NAME : params.RELEASE_NAME
Map buildInfo = [
"project_id": service,
"build_id": env.BUILD_ID,
"release_id": env.RELEASE_ID,
"git_tag": env.GIT_TAG,
"purpose": env.PURPOSE,
]
createBuild(
buildInfo,
rmsSupportedEnvironment.production
)
}
}
}
}
}
stage('Deploy') {
when {
not { expression { isPr } }
not { expression { skip } }
not { expression { return params.RELEASE_BUILD } }
}
steps {
script {
lastStage = env.STAGE_NAME
env.ENVIRONMENT = (isHotfix) ? 'rc' : 'staging'
marathonDeploy(
serviceName: service,
tag: env.BUILD_ID,
environment: env.ENVIRONMENT
)
}
}
post {
success {
script {
if (isHotfix) {
Map deployInfo = [
"build_id": env.BUILD_ID,
"environment": env.ENVIRONMENT,
]
createDeployment(
deployInfo,
rmsSupportedEnvironment.production
)
}
}
}
}
}
}
post {
failure {
script {
boolean buildingMain = (env.JOB_NAME.contains("${service}/main"))
if (buildingMain) {
teamsMessage(
message: "[${currentBuild.fullDisplayName}](${env.BUILD_URL}) has failed in stage ${lastStage}",
webhookCredentialID: WEBHOOK_ID
)
}
}
}
}
}