forked from department-of-veterans-affairs/vets-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
90 lines (76 loc) · 2.53 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
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('Scheudle Review Instance Creation') {
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: env.THE_BRANCH),
stringParam(name: 'content_branch', value: 'master'),
stringParam(name: 'source_repo', value: 'vets-api'),
], wait: false
}
}
stage('Build AMI') {
when { anyOf { 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 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
}
}
}
post {
always {
sh 'env=$RAILS_ENV make down'
deleteDir() /* clean up our workspace */
}
failure {
script {
if (env.BRANCH_NAME == 'master') {
slackSend message: "Failed vets-api CI on branch: `${env.THE_BRANCH}`! ${env.RUN_DISPLAY_URL}".stripMargin(),
color: 'danger',
failOnError: true
}
}
}
}
}