Repository navigation
Expand file tree
/
Copy pathJenkinsfile
More file actions
98 lines (85 loc) · 3.59 KB
/
Copy pathJenkinsfile
File metadata and controls
98 lines (85 loc) · 3.59 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
#!groovy
node {
try {
env.COMPOSE_PROJECT_NAME = "open-apparel-registry-${env.BRANCH_NAME}"
// Checkout the proper revision into the workspace.
stage('checkout') {
checkout scm
}
env.AWS_PROFILE = 'open-apparel-registry'
env.AWS_DEFAULT_REGION = 'eu-west-1'
env.OAR_SETTINGS_BUCKET = 'openapparelregistry-testing-config-eu-west-1'
stage('setup') {
wrap([$class: 'AnsiColorBuildWrapper']) {
sh './scripts/bootstrap'
}
}
stage('cibuild') {
wrap([$class: 'AnsiColorBuildWrapper']) {
sh './scripts/cibuild'
}
}
env.OAR_SETTINGS_BUCKET = 'openapparelregistry-staging-config-eu-west-1'
if (env.BRANCH_NAME == 'develop' || env.BRANCH_NAME.startsWith('test/') || env.BRANCH_NAME.startsWith('release/') || env.BRANCH_NAME.startsWith('hotfix/')) {
// Publish container images built and tested during `cibuild`
// to the private Amazon Container Registry tagged with the
// first seven characters of the revision SHA.
stage('cipublish') {
// Decode the ECR endpoint stored within Jenkins.
withCredentials([[$class: 'StringBinding',
credentialsId: 'OAR_AWS_ECR_ENDPOINT',
variable: 'OAR_AWS_ECR_ENDPOINT']]) {
wrap([$class: 'AnsiColorBuildWrapper']) {
sh './scripts/cipublish'
}
}
}
// Plan and apply the current state of the staging infrastructure
// as outlined by whatever branch of the `open-apparel-registry`
// repository passes the conditional above (`develop`,
// `test/*`, `release/*`, `hotfix/*`).
stage('infra') {
// Use `git` to get the primary repository's current commmit SHA and
// set it as the value of the `GIT_COMMIT` environment variable.
env.GIT_COMMIT = sh(returnStdout: true, script: 'git rev-parse --short HEAD').trim()
// Environment used in Rollbar deploy notifications.
// https://docs.rollbar.com/reference#post-deploy
env.OAR_DEPLOYMENT_ENVIRONMENT = 'staging'
wrap([$class: 'AnsiColorBuildWrapper']) {
sh 'docker-compose -f docker-compose.ci.yml run --rm terraform ./scripts/infra plan'
withCredentials([[$class: 'StringBinding',
credentialsId: 'OAR_ROLLBAR_ACCESS_TOKEN',
variable: 'OAR_ROLLBAR_ACCESS_TOKEN']]) {
sh 'docker-compose -f docker-compose.ci.yml run --rm terraform ./scripts/infra apply'
}
}
}
}
stage('notify') {
if (currentBuild.currentResult == 'SUCCESS' && currentBuild.previousBuild?.result != 'SUCCESS') {
def slackMessage = ":jenkins: *Open Apparel Registry (${env.BRANCH_NAME}) #${env.BUILD_NUMBER}*"
if (env.CHANGE_TITLE) {
slackMessage += "\n${env.CHANGE_TITLE} - ${env.CHANGE_AUTHOR}"
}
slackMessage += "\n<${env.BUILD_URL}|View Build>"
slackSend channel: '#oar', color: 'good', message: slackMessage
}
}
} catch (err) {
// Some exception was raised in the `try` block above. Assemble
// an appropirate error message for Slack.
def slackMessage = ":jenkins-angry: *Open Apparel Registry (${env.BRANCH_NAME}) #${env.BUILD_NUMBER}*"
if (env.CHANGE_TITLE) {
slackMessage += "\n${env.CHANGE_TITLE} - ${env.CHANGE_AUTHOR}"
}
slackMessage += "\n<${env.BUILD_URL}|View Build>"
slackSend channel: '#oar', color: 'danger', message: slackMessage
// Re-raise the exception so that the failure is propagated to
// Jenkins.
throw err
} finally {
// Pass or fail, ensure that the services and networks
// created by Docker Compose are torn down.
sh 'docker-compose down -v'
}
}