-
Notifications
You must be signed in to change notification settings - Fork 45
/
Jenkinsfile
110 lines (99 loc) · 4.6 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
#!groovy
node {
try {
// Checkout the proper revision into the workspace.
stage('checkout') {
checkout([
$class: 'GitSCM',
branches: scm.branches,
extensions: scm.extensions + [[$class: 'CloneOption', noTags: false, reference: '', shallow: false]],
userRemoteConfigs: scm.userRemoteConfigs
])
}
env.AWS_DEFAULT_REGION = 'us-east-1'
env.RF_ARTIFACTS_BUCKET = 'rasterfoundry-global-artifacts-us-east-1'
// Execute `cibuild` wrapped within a plugin that translates
// ANSI color codes to something that renders inside the Jenkins
// console.
stage('cibuild') {
env.RF_SETTINGS_BUCKET = 'rasterfoundry-testing-config-us-east-1'
wrap([$class: 'AnsiColorBuildWrapper']) {
sh 'scripts/cibuild'
}
}
env.RF_SETTINGS_BUCKET = 'rasterfoundry-staging-config-us-east-1'
if (env.BRANCH_NAME == 'develop' || env.BRANCH_NAME =~ /test\// || env.BRANCH_NAME =~ /hotfix\//) {
env.RF_DEPLOYMENT_BRANCH = 'develop'
env.RF_DEPLOYMENT_ENVIRONMENT = "Staging"
// 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 `AWS_ECR_ENDPOINT` credential stored within
// Jenkins. In includes the Amazon ECR registry endpoint.
withCredentials([[$class: 'StringBinding',
credentialsId: 'AWS_ECR_ENDPOINT',
variable: 'AWS_ECR_ENDPOINT'],
[$class: 'StringBinding',
credentialsId: 'SONATYPE_USERNAME',
variable: 'SONATYPE_USERNAME'],
[$class: 'StringBinding',
credentialsId: 'SONATYPE_PASSWORD',
variable: 'SONATYPE_PASSWORD'],
[$class: 'StringBinding',
credentialsId: 'GPG_KEY',
variable: 'GPG_KEY'],
[$class: 'StringBinding',
credentialsId: 'GPG_KEY_ID',
variable: 'GPG_KEY_ID']]) {
wrap([$class: 'AnsiColorBuildWrapper']) {
sh './scripts/cipublish'
}
}
}
// Plan and apply the current state of the instracture as
// outlined by the `master` branch of the deployment repository.
//
// Also, use the container image revision referenced above to
// cycle in the newest version of the application into Amazon
// ECS.
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()
checkout scm: [$class: 'GitSCM',
branches: [[name: env.RF_DEPLOYMENT_BRANCH]],
extensions: [[$class: 'RelativeTargetDirectory',
relativeTargetDir: 'raster-foundry-deployment']],
userRemoteConfigs: [[credentialsId: '3bc1e878-814a-43d1-864e-2e378ebddb0f',
url: 'https://github.com/azavea/raster-foundry-deployment.git']]]
dir('raster-foundry-deployment') {
wrap([$class: 'AnsiColorBuildWrapper']) {
sh 'docker-compose -f docker-compose.yml -f docker-compose.ci.yml run --rm terraform ./scripts/infra plan'
withCredentials([[$class: 'StringBinding',
credentialsId: 'ROLLBAR_ACCESS_TOKEN',
variable: 'ROLLBAR_ACCESS_TOKEN']]) {
sh 'docker-compose -f docker-compose.yml -f docker-compose.ci.yml run --rm terraform ./scripts/infra apply'
}
}
}
}
}
} catch (err) {
// Some exception was raised in the `try` block above. Assemble
// an appropirate error message for Slack.
def slackMessage = ":jenkins-angry: *raster-foundry (${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 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 --remove-orphans'
}
}