-
Notifications
You must be signed in to change notification settings - Fork 11
/
Jenkinsfile
69 lines (65 loc) · 1.69 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
pipeline {
agent { label 'master' }
stages {
stage ('Build') {
steps {
sh """
docker build \
--pull \
--no-cache \
--target builder .
"""
}
}
stage ('Run Unit & Integration Tests') {
steps {
// Run the Unit Tests
sh """
docker build \
--target unit-tester .
"""
// Run the Integration Tests
sh """
docker build \
--target integration-tester \
-t img-${GIT_COMMIT} .
"""
}
post {
// Parse the test results so they appear in BlueOcean UI
success {
sh "docker run -t -d --rm --name ctr-${GIT_COMMIT} img-${GIT_COMMIT}"
sh "docker cp ctr-${GIT_COMMIT}:/app/. results"
sh "docker rm --force ctr-${GIT_COMMIT}"
junit 'results/**/*_results.xml'
}
}
}
stage ('Docker Build') {
steps {
sh """
docker build \
--target production \
-t flask-calculator-img:latest .
"""
}
}
stage ('Deploy') {
when {
// Only deploy the application when on 'master' branch
branch 'master'
}
steps {
// Remove any existing running containers
sh 'docker container rm --force flask-calculator-app || true'
// Run the new Docker Image
sh 'docker container run --name flask-calculator-app -p 5000:5000 -d flask-calculator-img:latest'
}
post {
success {
sh "echo The app can be tested by visiting: http://`curl -s http://169.254.169.254/latest/meta-data/public-hostname`:5000"
}
}
}
}
}