forked from department-of-veterans-affairs/vets-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
138 lines (118 loc) · 4.57 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
@Library('va.gov-devops-jenkins-lib') _
import org.kohsuke.github.GitHub
env.CONCURRENCY = 10
node('vetsgov-general-purpose') {
properties([[$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', daysToKeepStr: '60']],
parameters([choice(name: "cmsEnvBuildOverride",
description: "Choose an environment to run a content only build. Select 'none' to run the regular pipeline.",
choices: ["none", "dev", "staging"].join("\n"))])]);
// Checkout vets-website code
dir("vets-website") {
checkout scm
ref = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
}
def commonStages = load "vets-website/jenkins/common.groovy"
// setupStage
dockerContainer = commonStages.setup()
stage('Lint|Security|Unit') {
if (params.cmsEnvBuildOverride != 'none') { return }
try {
parallel (
lint: {
dockerContainer.inside(commonStages.DOCKER_ARGS) {
sh "cd /application && npm --no-color run lint"
}
},
// Check package.json for known vulnerabilities
security: {
retry(3) {
dockerContainer.inside(commonStages.DOCKER_ARGS) {
sh "cd /application && npm run security-check"
}
}
},
unit: {
dockerContainer.inside(commonStages.DOCKER_ARGS) {
sh "cd /application && npm --no-color run test:coverage"
}
}
)
} catch (error) {
commonStages.slackNotify()
throw error
} finally {
dir("vets-website") {
step([$class: 'JUnitResultArchiver', testResults: 'test-results.xml'])
}
}
}
// Perform a build for each build type
envsUsingDrupalCache = commonStages.buildAll(ref, dockerContainer, params.cmsEnvBuildOverride != 'none')
// Run E2E and accessibility tests
stage('Integration') {
if (commonStages.shouldBail() || !commonStages.VAGOV_BUILDTYPES.contains('vagovprod')) { return }
dir("vets-website") {
try {
parallel (
e2e: {
sh "export IMAGE_TAG=${commonStages.IMAGE_TAG} && docker-compose -p e2e up -d && docker-compose -p e2e run --rm --entrypoint=npm -e BABEL_ENV=test -e BUILDTYPE=vagovprod vets-website --no-color run nightwatch:docker"
try {
sh "docker-compose -p e2e run --rm --entrypoint npm -e BABEL_ENV=test -e BUILDTYPE=vagovprod vets-website --no-color run test:puppeteer:docker"
} catch (error) {
commonStages.puppeteerNotification()
throw error
}
},
accessibility: {
sh "export IMAGE_TAG=${commonStages.IMAGE_TAG} && docker-compose -p accessibility up -d && docker-compose -p accessibility run --rm --entrypoint=npm -e BABEL_ENV=test -e BUILDTYPE=vagovprod vets-website --no-color run nightwatch:docker -- --env=accessibility"
}
)
} catch (error) {
commonStages.slackNotify()
throw error
} finally {
sh "docker-compose -p e2e down --remove-orphans"
sh "docker-compose -p accessibility down --remove-orphans"
step([$class: 'JUnitResultArchiver', testResults: 'logs/nightwatch/**/*.xml'])
}
}
}
commonStages.prearchiveAll(dockerContainer)
commonStages.archiveAll(dockerContainer, ref);
commonStages.cacheDrupalContent(dockerContainer, envsUsingDrupalCache);
// stage('Review') {
// if (commonStages.shouldBail()) {
// currentBuild.result = 'ABORTED'
// return
// }
//
// try {
// if (!commonStages.isReviewable()) {
// return
// }
// build job: 'deploys/vets-review-instance-deploy', parameters: [
// stringParam(name: 'devops_branch', value: 'master'),
// stringParam(name: 'api_branch', value: 'master'),
// stringParam(name: 'web_branch', value: env.BRANCH_NAME),
// stringParam(name: 'source_repo', value: 'vets-website'),
// ], wait: false
// } catch (error) {
// commonStages.slackNotify()
// throw error
// }
// }
stage('Deploy dev or staging') {
try {
if (!commonStages.isDeployable()) { return }
if (commonStages.IS_DEV_BRANCH && commonStages.VAGOV_BUILDTYPES.contains('vagovdev')) {
commonStages.runDeploy('deploys/vets-website-vagovdev', ref, false)
}
if (commonStages.IS_STAGING_BRANCH && commonStages.VAGOV_BUILDTYPES.contains('vagovstaging')) {
commonStages.runDeploy('deploys/vets-website-vagovstaging', ref, false)
}
} catch (error) {
commonStages.slackNotify()
throw error
}
}
}