-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
117 lines (110 loc) · 4.04 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
pipeline {
agent any
options {
buildDiscarder(logRotator(
numToKeepStr: '10',
artifactNumToKeepStr: '10'
))
}
/*
https://stackoverflow.com/a/44155346
daysToKeepStr: history is only kept up to this days.
numToKeepStr: only this number of build logs are kept.
artifactDaysToKeepStr: artifacts are only kept up to this days.
artifactNumToKeepStr: only this number of builds have their artifacts kept.
*/
// environment {
// }
stages {
stage('Lint') {
steps {
sh 'npm install eslint eslint-plugin-react babel-eslint'
sh 'npm run lint'
}
}
stage('Build') {
steps {
script {
NODE_VERSION = sh(
returnStdout: true,
script: 'node -v'
).trim()
NPM_VERSION = sh(
returnStdout: true,
script: 'npm -v'
).trim()
}
echo "NODE: " + NODE_VERSION + ", " + "NPM: " + NPM_VERSION
sh 'npm install'
sh 'npm run build'
}
}
stage('Analyze') {
steps {
parallel (
"test" : {
sh 'npm run test.ci'
},
"build stats": {
echo 'TODO: build/dist analysis (jenkins plugin?) - https://survivejs.com/webpack/optimizing/build-analysis/'
sh 'npm run bundle.stats'
},
"audit": {
sh 'mv .npmrc .no-npmrc && npm i --package-lock-only && mv .no-npmrc .npmrc && npm audit'
}
)
}
post {
always {
junit 'build/reports/*.xml'
cobertura coberturaReportFile: 'build/coverage/cobertura-coverage.xml'
}
}
}
stage('Deploy') {
steps {
sh 'npm run clean'
script {
ENVMAP = [
COOKIE_SECRET: UUID.randomUUID(),
PORT: 3777,
MONGO: "",
REDDIS: ""
]
ENVTEXT = ENVMAP.inject([]) { result, entry ->
result << "${entry.key}=${entry.value.toString()}"
}.join('\n')
}
writeFile(file: ".env", text: ENVTEXT, encoding: "UTF-8")
sshPublisher(
publishers: [sshPublisherDesc(
configName: 'ubuntu',
transfers: [sshTransfer(
cleanRemote: true,
excludes: '',
execCommand: 'touch ./deploy/it-happened.done && du -hd1 ./deploy/cents/',
execTimeout: 120000,
flatten: false,
makeEmptyDirs: true,
noDefaultExcludes: false,
patternSeparator: '[, ]+',
remoteDirectory: '/deploy/cents/',
remoteDirectorySDF: false,
removePrefix: '',
sourceFiles: 'dist/**, service/**, node_modules/**, deploy.sh, docker-compose.yml, .env'
)],
usePromotionTimestamp: false,
useWorkspaceInPromotion: false,
verbose: false
)]
)
}
}
}
post {
always {
archiveArtifacts artifacts: 'webpack-stats.json', fingerprint: true
// archiveArtifacts artifacts: 'node_modules/**, dist/**, server/**, service/**, deploy.sh, docker-compose.yml', fingerprint: true
}
}
}