-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
67 lines (64 loc) · 2.39 KB
/
Jenkinsfile
File metadata and controls
67 lines (64 loc) · 2.39 KB
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
pipeline {
agent any
options {
disableResume()
}
stages {
stage('Kill any older builds') {
steps {
script {
def buildNumber = env.BUILD_NUMBER as int
if (buildNumber > 1) milestone(buildNumber - 1)
milestone(buildNumber)
}
}
}
stage('Build images') {
steps {
sh 'docker-compose -f docker-compose-ci.yml build --parallel'
}
}
stage('Run Client Tests') {
steps {
sh 'docker-compose -f docker-compose-ci.yml run client npm test'
}
}
stage('Run Server Tests') {
steps {
sh 'docker-compose -f docker-compose-ci.yml run server python manage.py test'
}
}
stage('Deploy to Server') {
when {
environment name: 'CHANGE_TARGET', value: 'master'
}
steps {
script {
withCredentials([file(credentialsId: 'swu-prod-env', variable: 'FILE_PATH')]) {
// Prepare production environment vars
def environment_vars = readFile "${FILE_PATH}"
writeFile file: 'env.prod', text: "${environment_vars}"
}
withCredentials([sshUserPrivateKey(credentialsId: 'ssh-instance-key', keyFileVariable: 'keyFile', usernameVariable: 'username')]) {
def remote = [:]
remote.name = "$AWS_INSTANCE_IP_ADDRESS"
remote.host = "$AWS_INSTANCE_IP_ADDRESS"
remote.user = username
remote.identityFile = keyFile
remote.allowAnyHosts = true
sshCommand remote: remote, command: "sudo rm -rf /tmp/workspace"
sshPut remote: remote, from: '.', into: '/tmp'
sshScript remote: remote, script: "deployment/scripts/deploy-application.sh"
}
}
}
}
}
post {
always {
echo 'Running cleanup'
sh 'docker-compose -f docker-compose-ci.yml down --rmi all --volumes || true'
sh 'docker-compose -f docker-compose-ci.yml rm -f -v -s || true'
}
}
}