forked from department-of-veterans-affairs/vets-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
158 lines (134 loc) · 4.36 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
dev_branch = 'master'
staging_branch = 'master'
main_branch = 'master'
pipeline {
environment {
DOCKER_IMAGE = env.BUILD_TAG.replaceAll(/[%\/]/, '')
// for PRs, BRANCH_NAME = PR-<ID>. for branches in the remote w/o a PR, BRANCH_NAME = <the name of the branch>
// THE_BRANCH is a hack to normalize this value depending on if Jenkins "discovered" using "branch" or "pull-request"
THE_BRANCH = "${env.CHANGE_BRANCH != null ? env.CHANGE_BRANCH : env.BRANCH_NAME}"
CI = "true"
RAILS_ENV = "test"
}
options {
buildDiscarder(logRotator(daysToKeepStr: '60'))
}
agent {
label 'vetsgov-general-purpose'
}
stages {
stage('Checkout Code') {
steps {
checkout scm
}
}
stage('Build Docker Images'){
steps {
withCredentials([string(credentialsId: 'sidekiq-enterprise-license', variable: 'BUNDLE_ENTERPRISE__CONTRIBSYS__COM')]) {
sh 'env=$RAILS_ENV make build'
}
}
}
stage('Setup Testing DB') {
steps {
sh 'env=$RAILS_ENV make db'
}
}
stage('Lint') {
steps {
sh 'env=$RAILS_ENV make lint'
}
}
stage('Security Scan') {
steps {
sh 'env=$RAILS_ENV make security'
}
}
stage('Run tests') {
steps {
sh 'env=$RAILS_ENV make spec'
}
post {
success {
archiveArtifacts artifacts: "coverage/**"
publishHTML(target: [reportDir: 'coverage', reportFiles: 'index.html', reportName: 'Coverage', keepAll: true])
junit 'log/*.xml'
}
}
}
stage('Run Danger Bot') {
steps {
withCredentials([string(credentialsId: 'danger-github-api-token', variable: 'DANGER_GITHUB_API_TOKEN')]) {
sh 'env=$RAILS_ENV make danger'
}
}
}
stage('Review') {
when { not { branch 'master' } }
steps {
build job: 'deploys/vets-review-instance-deploy', parameters: [
stringParam(name: 'devops_branch', value: 'master'),
stringParam(name: 'api_branch', value: env.THE_BRANCH),
stringParam(name: 'web_branch', value: 'master'),
stringParam(name: 'source_repo', value: 'vets-api'),
], wait: false
}
}
stage('Build AMI') {
when { anyOf { branch dev_branch; branch staging_branch; branch main_branch } }
steps {
// hack to get the commit hash, some plugin is swallowing git variables and I can't figure out which one
script {
commit = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
}
build job: 'builds/vets-api', parameters: [
booleanParam(name: 'notify_slack', value: true),
stringParam(name: 'ref', value: commit),
booleanParam(name: 'release', value: false),
], wait: true
}
}
stage('Deploy dev') {
when { branch dev_branch }
steps {
build job: 'deploys/vets-api-server-vagov-dev', parameters: [
booleanParam(name: 'notify_slack', value: true),
booleanParam(name: 'migration_status', value: true),
stringParam(name: 'ref', value: commit),
], wait: false
build job: 'deploys/vets-api-worker-vagov-dev', parameters: [
booleanParam(name: 'notify_slack', value: true),
booleanParam(name: 'migration_status', value: false),
stringParam(name: 'ref', value: commit),
], wait: false
}
}
stage('Deploy staging') {
when { branch staging_branch }
steps {
build job: 'deploys/vets-api-server-vagov-staging', parameters: [
booleanParam(name: 'notify_slack', value: true),
booleanParam(name: 'migration_status', value: true),
stringParam(name: 'ref', value: commit),
], wait: false
build job: 'deploys/vets-api-worker-vagov-staging', parameters: [
booleanParam(name: 'notify_slack', value: true),
booleanParam(name: 'migration_status', value: false),
stringParam(name: 'ref', value: commit),
], wait: false
}
}
}
post {
always {
sh 'env=$RAILS_ENV make down'
deleteDir() /* clean up our workspace */
}
failure {
when { branch 'master' }
slackSend message: "Failed vets-api CI on branch: `${env.THE_BRANCH}`! ${env.RUN_DISPLAY_URL}".stripMargin(),
color: 'danger',
failOnError: true
}
}
}