-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
142 lines (132 loc) · 5.9 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
pipeline {
agent none
environment {
PIPELINE_VERSION = build.pipelineVersion()
}
stages {
stage('Pre build') {
steps {
setBuildDisplayName to: env.PIPELINE_VERSION
sendBuildNotification()
}
}
stage('Test and build') {
agent { label 'ubuntu && 20.04' }
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 --gemfile=Gemfile.deployment --deployment'
}
}
stage('Run checks') {
steps {
sh label: 'Check JSON syntax', script: 'bundle exec --gemfile=Gemfile.deployment rake jsonlint'
}
}
stage('Build artifact') {
steps {
sh label: 'Build artifact', script: "bundle exec --gemfile=Gemfile.deployment rake build_artifact ARTIFACT_VERSION=${env.ARTIFACT_VERSION}"
archiveArtifacts artifacts: "pkg/*${env.ARTIFACT_VERSION}*.tar.gz", onlyIfSuccessful: true
}
}
}
post {
cleanup {
cleanWs()
}
}
}
stage('Deploy to Acceptance') {
agent { label 'ubuntu && 20.04' }
options { skipDefaultCheckout() }
environment {
APPLICATION_ENVIRONMENT = 'acceptance'
BUCKET = 'assets-acc.uit.be'
DISTRIBUTION_ID = 'EGX9C66I8R065'
}
steps {
copyArtifacts filter: 'pkg/*.tar.gz', projectName: env.JOB_NAME, flatten: true, selector: specific(env.BUILD_NUMBER)
untar file: findFiles(glob: '*.tar.gz')[0].path, quiet: true
sh label: 'Upload versions.json', script: "bundle exec --gemfile=Gemfile.deployment rake s3_upload BUCKET=${env.BUCKET}"
sh label: 'Invalidate cache for /versions endpoint', script: "bundle exec --gemfile=Gemfile.deployment rake invalidate_cache DISTRIBUTION_ID=${env.DISTRIBUTION_ID}"
}
post {
always {
sendBuildNotification to: '#ups-ops', message: "Pipeline <${env.RUN_DISPLAY_URL}|${util.getJobDisplayName()} [${currentBuild.displayName}]>: deployed to *${env.APPLICATION_ENVIRONMENT}*"
}
cleanup {
cleanWs()
}
}
}
stage('Deploy to Testing') {
input { message "Deploy to Testing?" }
agent { label 'ubuntu && 20.04' }
options { skipDefaultCheckout() }
environment {
APPLICATION_ENVIRONMENT = 'testing'
BUCKET = 'assets-test.uit.be'
DISTRIBUTION_ID = 'E23GDOYWUCPRUE'
}
steps {
copyArtifacts filter: 'pkg/*.tar.gz', projectName: env.JOB_NAME, flatten: true, selector: specific(env.BUILD_NUMBER)
untar file: findFiles(glob: '*.tar.gz')[0].path, quiet: true
sh label: 'Upload versions.json', script: "bundle exec --gemfile=Gemfile.deployment rake s3_upload BUCKET=${env.BUCKET}"
sh label: 'Invalidate cache for /versions endpoint', script: "bundle exec --gemfile=Gemfile.deployment rake invalidate_cache DISTRIBUTION_ID=${env.DISTRIBUTION_ID}"
}
post {
always {
sendBuildNotification to: '#ups-ops', message: "Pipeline <${env.RUN_DISPLAY_URL}|${util.getJobDisplayName()} [${currentBuild.displayName}]>: deployed to *${env.APPLICATION_ENVIRONMENT}*"
}
cleanup {
cleanWs()
}
}
}
stage('Deploy to Production') {
input { message "Deploy to Production?" }
agent { label 'ubuntu && 20.04' }
options { skipDefaultCheckout() }
environment {
APPLICATION_ENVIRONMENT = 'production'
BUCKET = 'assets.uit.be'
DISTRIBUTION_ID = 'EEXNZ7UEW1WBC'
}
steps {
copyArtifacts filter: 'pkg/*.tar.gz', projectName: env.JOB_NAME, flatten: true, selector: specific(env.BUILD_NUMBER)
untar file: findFiles(glob: '*.tar.gz')[0].path, quiet: true
sh label: 'Upload versions.json', script: "bundle exec --gemfile=Gemfile.deployment rake s3_upload BUCKET=${env.BUCKET}"
sh label: 'Invalidate cache for /versions endpoint', script: "bundle exec --gemfile=Gemfile.deployment rake invalidate_cache DISTRIBUTION_ID=${env.DISTRIBUTION_ID}"
}
post {
always {
sendBuildNotification to: '#ups-ops', message: "Pipeline <${env.RUN_DISPLAY_URL}|${util.getJobDisplayName()} [${currentBuild.displayName}]>: deployed to *${env.APPLICATION_ENVIRONMENT}*"
}
cleanup {
cleanWs()
}
}
}
stage('Tag release') {
agent { label 'ubuntu && 20.04' }
steps {
copyArtifacts filter: 'pkg/*.tar.gz', projectName: env.JOB_NAME, flatten: true, selector: specific(env.BUILD_NUMBER)
tagRelease commitHash: artifact.metadata(artifactFilter: '*.tar.gz', field: 'git-ref')
}
post {
cleanup {
cleanWs()
}
}
}
}
post {
always {
sendBuildNotification()
}
}
}