-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
120 lines (117 loc) · 3.31 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
@Library('socrata-pipeline-library')
String service = 'region-coder'
String project_wd = '.'
boolean isPr = env.CHANGE_ID != null
boolean lastStage
def sbtbuild = new com.socrata.SBTBuild(steps, service, project_wd)
def dockerize = new com.socrata.Dockerize(steps, service, BUILD_NUMBER)
pipeline {
options {
ansiColor('xterm')
disableConcurrentBuilds(abortPrevious: true)
buildDiscarder(logRotator(numToKeepStr: '20'))
timeout(time: 20, unit: 'MINUTES')
}
parameters {
string(name: 'AGENT', defaultValue: 'build-worker', 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?')
}
agent {
label params.AGENT
}
environment {
WEBHOOK_ID = 'WEBHOOK_IQ'
SCALA_VERSION = '2.10'
}
stages {
stage('Checkout Release Tag') {
when {
expression { return params.RELEASE_BUILD }
}
steps {
script {
String repoURL = sh(script: "git config --get remote.origin.url", returnStdout: true).trim()
String closestTag = sh(script: "git describe --abbrev=0", returnStdout: true).trim()
steps.checkout([$class: 'GitSCM',
branches: [[name: "refs/tags/${closestTag}"]],
extensions: [[$class: 'LocalBranch', localBranch: "**"]],
gitTool: 'Default',
userRemoteConfigs: [[credentialsId: 'pipelines-token', url: repoURL]]
])
}
}
}
stage('Build') {
steps {
script {
lastStage = env.STAGE_NAME
sbtbuild.setScalaVersion(env.SCALA_VERSION)
sbtbuild.build()
}
}
}
stage('Docker Build') {
when {
not { expression { isPr } }
}
steps {
script {
lastStage = env.STAGE_NAME
env.DOCKER_TAG = dockerize.dockerBuildWithDefaultTag(
version: sbtbuild.getServiceVersion(),
sha: env.GIT_COMMIT,
path: sbtbuild.getDockerPath(),
artifacts: [sbtbuild.getDockerArtifact()]
)
}
}
}
stage('Publish') {
when {
not { expression { isPr } }
}
steps {
script {
if (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
}
}
}
stage('Deploy') {
when {
not { expression { isPr } }
}
steps {
script {
lastStage = env.STAGE_NAME
String environment = (params.RELEASE_BUILD) ? 'rc' : 'staging'
marathonDeploy(
serviceName: service,
tag: env.BUILD_ID,
environment: environment
)
}
}
}
}
post {
failure {
script {
if (!isPr) {
teamsMessage(
message: "Build [${currentBuild.fullDisplayName}](${env.BUILD_URL}) has failed in stage ${lastStage}",
webhookCredentialID: WEBHOOK_ID
)
}
}
}
}
}