-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
185 lines (173 loc) · 6.84 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
pipeline {
agent none
environment {
PIPELINE_VERSION = build.pipelineVersion()
REPOSITORY_NAME = 'uitdatabank-search-api'
}
stages {
stage('Pre build') {
steps {
setBuildDisplayName to: env.PIPELINE_VERSION
sendBuildNotification()
}
}
stage('Setup and build') {
agent { label 'ubuntu && 20.04 && php7.4' }
environment {
GIT_SHORT_COMMIT = build.shortCommitRef()
ARTIFACT_VERSION = "${env.PIPELINE_VERSION}" + '+sha.' + "${env.GIT_SHORT_COMMIT}"
}
stages {
stage('Setup') {
steps {
sh label: 'Install rubygems', script: 'bundle install --deployment'
}
}
stage('Build') {
steps {
sh label: 'Build binaries', script: 'bundle exec rake build'
}
}
stage('Build artifact') {
steps {
sh label: 'Build artifact', script: "bundle exec rake build_artifact ARTIFACT_VERSION=${env.ARTIFACT_VERSION}"
archiveArtifacts artifacts: "pkg/*${env.ARTIFACT_VERSION}*.deb", onlyIfSuccessful: true
}
}
}
post {
cleanup {
cleanWs()
}
}
}
stage('Upload artifact') {
agent any
options { skipDefaultCheckout() }
steps {
copyArtifacts filter: 'pkg/*.deb', projectName: env.JOB_NAME, flatten: true, selector: specific(env.BUILD_NUMBER)
uploadAptlyArtifacts artifacts: '*.deb', repository: env.REPOSITORY_NAME
createAptlySnapshot name: "${env.REPOSITORY_NAME}-${env.PIPELINE_VERSION}", repository: env.REPOSITORY_NAME
}
post {
cleanup {
cleanWs()
}
}
}
stage('Deploy to development') {
agent any
options { skipDefaultCheckout() }
environment {
APPLICATION_ENVIRONMENT = 'development'
}
steps {
publishAptlySnapshot snapshotName: "${env.REPOSITORY_NAME}-${env.PIPELINE_VERSION}", publishTarget: "${env.REPOSITORY_NAME}-${env.APPLICATION_ENVIRONMENT}", distributions: 'focal'
}
}
stage('Deploy to acceptance') {
agent { label 'ubuntu && 20.04' }
options { skipDefaultCheckout() }
environment {
APPLICATION_ENVIRONMENT = 'acceptance'
}
steps {
publishAptlySnapshot snapshotName: "${env.REPOSITORY_NAME}-${env.PIPELINE_VERSION}", publishTarget: "${env.REPOSITORY_NAME}-${env.APPLICATION_ENVIRONMENT}", distributions: 'focal'
triggerDeployment nodeName: 'uitdatabank-search-acc01'
}
post {
always {
sendBuildNotification to: '#upw-ops', message: "Pipeline <${env.RUN_DISPLAY_URL}|${util.getJobDisplayName()} [${currentBuild.displayName}]>: deployed to *${env.APPLICATION_ENVIRONMENT}*"
}
}
}
stage('Deploy to testing') {
input { message "Deploy to Testing?" }
agent { label 'ubuntu && 20.04' }
options { skipDefaultCheckout() }
environment {
APPLICATION_ENVIRONMENT = 'testing'
}
stages {
stage('Publish snapshot') {
steps {
publishAptlySnapshot snapshotName: "${env.JOB_NAME}-${env.PIPELINE_VERSION}", publishTarget: "${env.JOB_NAME}-${env.APPLICATION_ENVIRONMENT}", distributions: 'focal'
}
}
stage('Deploy') {
parallel {
stage('Deploy to first node') {
steps {
triggerDeployment nodeName: 'uitdatabank-search-test01'
}
}
stage('Deploy to second node') {
steps {
triggerDeployment nodeName: 'uitdatabank-search-test02'
}
}
}
}
}
post {
always {
sendBuildNotification to: '#upw-ops', message: "Pipeline <${env.RUN_DISPLAY_URL}|${util.getJobDisplayName()} [${currentBuild.displayName}]>: deployed to *${env.APPLICATION_ENVIRONMENT}*"
}
}
}
stage('Deploy to production') {
input { message "Deploy to Production?" }
agent { label 'ubuntu && 20.04' }
options { skipDefaultCheckout() }
environment {
APPLICATION_ENVIRONMENT = 'production'
}
stages {
stage('Publish snapshot') {
steps {
publishAptlySnapshot snapshotName: "${env.JOB_NAME}-${env.PIPELINE_VERSION}", publishTarget: "${env.JOB_NAME}-${env.APPLICATION_ENVIRONMENT}", distributions: 'focal'
}
}
stage('Deploy') {
parallel {
stage('Deploy to first node') {
steps {
triggerDeployment nodeName: 'uitdatabank-search-prod01'
}
}
stage('Deploy to second node') {
steps {
triggerDeployment nodeName: 'uitdatabank-search-prod02'
}
}
}
}
}
post {
always {
sendBuildNotification to: '#upw-ops', message: "Pipeline <${env.RUN_DISPLAY_URL}|${util.getJobDisplayName()} [${currentBuild.displayName}]>: deployed to *${env.APPLICATION_ENVIRONMENT}*"
}
cleanup {
cleanupAptlySnapshots repository: env.REPOSITORY_NAME
}
}
}
stage('Tag release') {
agent any
steps {
copyArtifacts filter: 'pkg/*.deb', projectName: env.JOB_NAME, flatten: true, selector: specific(env.BUILD_NUMBER)
tagRelease commitHash: artifact.metadata(artifactFilter: '*.deb', field: 'git-ref')
}
post {
cleanup {
cleanWs()
}
}
}
}
post {
always {
sendBuildNotification()
}
}
}