forked from department-of-veterans-affairs/vets-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
123 lines (107 loc) · 3.32 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
dev_branch = 'master'
staging_branch = 'master'
main_branch = 'master'
pipeline {
environment {
DOCKER_IMAGE = env.BUILD_TAG.replaceAll(/[%\/]/, '')
}
options {
buildDiscarder(logRotator(daysToKeepStr: '60'))
}
agent {
label 'vetsgov-general-purpose'
}
stages {
stage('Checkout Code') {
steps {
checkout scm
}
}
stage('Run tests') {
steps {
withCredentials([string(credentialsId: 'sidekiq-enterprise-license', variable: 'BUNDLE_ENTERPRISE__CONTRIBSYS__COM')]) {
withEnv(['RAILS_ENV=test', 'CI=true']) {
sh 'make ci'
}
}
}
post {
success {
archiveArtifacts artifacts: "coverage/**"
publishHTML(target: [reportDir: 'coverage', reportFiles: 'index.html', reportName: 'Coverage', keepAll: true])
junit 'log/*.xml'
}
}
}
stage('Review') {
when {
expression {
!['master', 'production'].contains(env.BRANCH_NAME)
}
}
steps {
build job: 'deploys/vets-review-instance-deploy', parameters: [
stringParam(name: 'devops_branch', value: 'master'),
stringParam(name: 'api_branch', value: env.BRANCH_NAME),
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),
stringParam(name: 'ref', value: commit),
], wait: false
build job: 'deploys/vets-api-worker-vagov-dev', parameters: [
booleanParam(name: 'notify_slack', value: true),
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),
stringParam(name: 'ref', value: commit),
], wait: false
build job: 'deploys/vets-api-worker-vagov-staging', parameters: [
booleanParam(name: 'notify_slack', value: true),
stringParam(name: 'ref', value: commit),
], wait: false
}
}
}
post {
always {
sh 'make clean'
deleteDir() /* clean up our workspace */
}
failure {
script {
if (env.BRANCH_NAME == 'master') {
slackSend message: "Failed vets-api CI on branch: `${env.BRANCH_NAME}`! ${env.RUN_DISPLAY_URL}".stripMargin(),
color: 'danger',
failOnError: true
}
}
}
}
}