-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile
123 lines (122 loc) · 4.01 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
pipeline {
environment {
DOCKER = credentials('docker-hub')
}
agent any
stages {
// Building your Test Images
stage('BUILD') {
parallel {
stage('Express Image') {
steps {
sh 'docker build -f express-image/Dockerfile \
-t nodeapp-dev:trunk .'
}
}
stage('Test-Unit Image') {
steps {
sh 'docker build -f testing-image/Dockerfile \
-t testing-image:latest .'
}
}
}
post {
failure {
echo 'I failed :('
// Uncomment this lines for email notifications on failure
// mail(from: "[email protected]",
// to: "[email protected]",
// subject: "This build failed! ${env.BUILD_TAG}",
// body: "Check the failure ${env.BUILD_URL}")
}
}
}
// Performing Software Tests
stage('TEST') {
parallel {
stage('Mocha Tests') {
steps {
sh 'docker run --name nodeapp-dev --network="bridge" -d \
-p 9000:9000 nodeapp-dev:trunk'
sh 'docker run --name testing-image -v $PWD:/JUnit --network="bridge" \
--link=nodeapp-dev -d -p 9001:9000 \
testing-image:latest'
}
}
stage('Quality Tests') {
steps {
sh 'docker login --username $DOCKER_USR --password $DOCKER_PSW'
sh 'docker tag nodeapp-dev:trunk damasosanoja/nodeapp-dev:latest'
sh 'docker push damasosanoja/nodeapp-dev:latest'
}
}
}
post {
success {
echo 'Success!'
// Uncomment this lines for email notifications on success
// mail(from: "[email protected]",
// to: "[email protected]",
// subject: "New test image available ${env.BUILD_TAG}",
// body: "Please review")
}
unstable {
echo 'I am unstable'
// Uncomment this lines for email notifications when marked as unstable (failed tests)
// mail(from: "[email protected]",
// to: "[email protected]",
// subject: "Unstable Test Results ${env.BUILD_TAG}",
// body: "The ${env.JOB_NAME} Project had an unstable test result \
// ${env.BUILD_URL} Branch: ${env.GIT_BRANCH} Commit: ${env.GIT_COMMIT}")
}
failure {
echo 'I failed :('
// Uncomment this lines for email notifications on failure
// mail(from: "[email protected]",
// to: "[email protected]",
// subject: "Test Stage failed! ${env.BUILD_TAG}",
// body: "Check the failure ${env.BUILD_URL}")
}
}
}
// Deploying your Software
stage('DEPLOY') {
when {
branch 'master' //only run these steps on the master branch
}
steps {
retry(3) {
timeout(time:10, unit: 'MINUTES') {
sh 'docker tag nodeapp-dev:trunk damasosanoja/nodeapp-prod:latest'
sh 'docker push damasosanoja/nodeapp-prod:latest'
sh 'docker save damasosanoja/nodeapp-prod:latest | gzip > nodeapp-prod-golden.tar.gz'
}
}
}
post {
failure {
sh 'docker stop nodeapp-dev testing-image'
sh 'docker system prune -f'
deleteDir()
}
}
}
// JUnit reports and artifacts saving
stage('REPORTS') {
steps {
junit 'reports.xml'
archiveArtifacts(artifacts: 'reports.xml', allowEmptyArchive: true)
archiveArtifacts(artifacts: 'nodeapp-prod-golden.tar.gz', allowEmptyArchive: true)
}
}
// Doing containers clean-up to avoid conflicts in future builds
stage('CLEAN-UP') {
steps {
sh 'docker stop nodeapp-dev testing-image'
sh 'docker system prune -f'
deleteDir()
}
}
}
}
//Testing Pipeline