-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
108 lines (78 loc) · 1.75 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
#!/usr/bin/groovy
pipeline {
agent any
options {
disableConcurrentBuilds()
}
environment {
PYTHONPATH = "${WORKSPACE}"
}
stages {
stage("Test - Unit tests") {
steps { runUnittests() }
}
stage("Build") {
steps { buildApp() }
}
stage("Deploy - Dev") {
steps { deploy('dev') }
}
stage("Test - UAT Dev") {
steps { runUAT(8888) }
}
stage("Deploy - Stage") {
steps { deploy('stage') }
}
stage("Test - UAT Stage") {
steps { runUAT(88) }
}
stage("Approve") {
steps { approve() }
}
stage("Deploy - Live") {
steps { deploy('live') }
}
stage("Test - UAT Live") {
steps { runUAT(80) }
}
}
}
// steps
def buildApp() {
def appImage = docker.build("django-on-jenkins/myapp:${BUILD_NUMBER}")
}
def deploy(environment) {
def containerName = ''
def port = ''
if ("${environment}" == 'dev') {
containerName = "app_dev"
port = "8888"
}
else if ("${environment}" == 'stage') {
containerName = "app_stage"
port = "88"
}
else if ("${environment}" == 'live') {
containerName = "app_live"
port = "80"
}
else {
println "Environment not valid"
System.exit(0)
}
// sh "docker ps -f name=${containerName} -q | xargs --no-run-if-empty docker stop"
// sh "docker ps -a -f name=${containerName} -q | xargs -r docker rm"
sh "docker run -d -p ${port}:5000 --name ${containerName} django-on-jenkins/myapp:${BUILD_NUMBER}"
}
def approve() {
timeout(time:1, unit:'DAYS') {
input('Do you want to deploy to live?')
}
}
def runUnittests() {
sh "pip3 install --no-cache-dir -r ./requirements.txt"
sh "python3 runtests.py"
}
def runUAT(port) {
sh "tests/runUAT.sh ${port}"
}