forked from HackerExperience/Helix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
141 lines (111 loc) · 3.27 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
#!/usr/bin/env groovy
retry(2) {
node('elixir') {
stage('Pre-build') {
step([$class: 'WsCleanup'])
env.BUILD_VERSION = sh(script: 'date +%Y.%m.%d%H%M', returnStdout: true).trim()
def ARTIFACT_PATH = "${env.BRANCH_NAME}/${env.BUILD_VERSION}"
checkout scm
sh 'mix local.hex --force'
sh 'mix local.rebar --force'
sh 'mix clean'
sh 'mix deps.get'
stash name: 'source', useDefaultExcludes: false
}
}
node('elixir') {
stage('Build [test]') {
timeout(3) {
step([$class: 'WsCleanup'])
unstash 'source'
withEnv (['MIX_ENV=test']) {
sh 'mix compile'
}
stash 'build-test'
}
}
}
node('elixir') {
stage('Build [prod]') {
timeout(3) {
step([$class: 'WsCleanup'])
unstash 'source'
withEnv (['MIX_ENV=prod']) {
sh 'mix compile'
sh 'mix release --env=prod --warnings-as-errors'
}
stash 'build-prod'
}
}
}
parallel (
'Lint': {
node('elixir') {
stage('Lint') {
timeout(3) {
step([$class: 'WsCleanup'])
unstash 'source'
unstash 'build-test'
withEnv (['MIX_ENV=test']) {
sh 'mix credo --strict'
}
}
}
}
},
'Type validation': {
node('elixir') {
stage('Type validation') {
timeout(30) {
step([$class: 'WsCleanup'])
unstash 'build-prod'
// HACK: mix complains if I don't run deps.get again, not sure why
sh 'mix deps.get'
// Reuse existing plt
sh 'cp ~/.mix/*prod*.plt* _build/prod || :'
withEnv (['MIX_ENV=prod']) {
sh 'mix dialyzer --halt-exit-status'
}
// Store newly generated plt
// Do it on two commands because we want it failing if .plt is not found
sh 'cp _build/prod/*.plt ~/.mix/'
sh 'cp _build/prod/*.plt.hash ~/.mix/'
}
}
}
},
'Tests': {
node('helix') {
stage('Tests') {
timeout(4) {
step([$class: 'WsCleanup'])
unstash 'source'
unstash 'build-test'
withEnv (['MIX_ENV=test', 'HELIX_SKIP_WARNINGS=false', 'HELIX_TEST_ENV=jenkins']) {
// HACK: mix complains if I don't run deps.get again, not sure why
// TODO: it's compiling everything again, find out why
sh 'mix deps.get'
// Unset debug flag, load env vars on ~/.profile & run mix test
sh '#!/bin/sh -e\n' + '. ~/.profile && mix test.full'
}
}
}
}
}
)
node('elixir') {
stage('Save artifacts') {
step([$class: 'WsCleanup'])
unstash 'build-prod'
sh "aws s3 cp _build/prod/rel/helix/releases/*/helix.tar.gz s3://he2-releases/helix/${env.BRANCH_NAME}/${env.BUILD_VERSION}.tar.gz --storage-class REDUCED_REDUNDANCY"
}
if (env.BRANCH_NAME == 'master'){
lock(resource: 'production-deployment', inversePrecedence: true) {
stage('Deploy') {
sh "ssh deployer deploy helix prod --branch master --version ${env.BUILD_VERSION}"
}
}
milestone()
}
}
}