forked from mrmaxsteel/CODE-devops-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
49 lines (46 loc) · 1.63 KB
/
Copy pathJenkinsfile
File metadata and controls
49 lines (46 loc) · 1.63 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
pipeline {
// Run this pipeline on the Jenkins Master (unless otherwise specified)
agent { label 'master' }
stages {
stage ('Run Unit & Integration Tests') {
// For this stage, tell Jenkins to build the agent form the dockerfile
agent {
dockerfile true
}
steps {
// Run the Unit Tests
sh 'py.test app/tests/unit -v --junitprefix=linux --junitxml unit_results.xml || true'
// Run the Integration Tests
sh 'py.test app/tests/integration -v --junitprefix=linux --junitxml integration_results.xml --debug || true'
sh 'cat pytestdebug.log'
}
post {
// Parse the test results so they appear in BlueOcean UI
always {
junit '**/*_results.xml'
}
}
}
stage ('Docker Build & Run') {
// Since no agent{} is specified, this stage will run on the Jenkins Master
when {
// Only run the application when on 'master' branch
branch 'master'
}
steps {
// Remove any existing running containers
sh 'docker container rm --force flask-calculator-app || true'
// Re-build the Docker Image and tag it as 'latest'
sh 'docker build --rm -t flask-calculator-img .'
sh 'docker tag flask-calculator-img flask-calculator-img:latest'
// 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"
}
}
}
}
}