forked from fhinkel/nodejs-hello-world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
81 lines (65 loc) · 2.95 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
//Jenkinsfile
node {
stage('Integration') {
withKubeConfig([credentialsId: 'jenkins-deployer-credentials', serverUrl: 'https://104.155.31.202']) {
sh 'kubectl create cm nodejs-app --from-file=src/ --namespace=myapp-integration -o=yaml --dry-run > deploy/cm.yaml'
sh 'kubectl apply -f deploy/ --namespace=myapp-integration'
try{
//Gathering Node.js app's external IP address
def ip = ''
def count = 0
def countLimit = 10
//Waiting loop for IP address provisioning
println("Waiting for IP address")
while(ip=='' && count<countLimit) {
sleep 30
ip = sh script: 'kubectl get svc --namespace=myapp-integration -o jsonpath="{.items[?(@.metadata.name==\'nginx-reverseproxy-service\')].status.loadBalancer.ingress[*].ip}"', returnStdout: true
ip=ip.trim()
count++
}
if(ip==''){
error("Not able to get the IP address. Aborting...")
}
else{
//Executing tests
//sh "chmod +x tests/integration-tests.sh && ./tests/integration-tests.sh ${ip}"
//Cleaning the integration environment
println("Cleaning integration environment...")
sh 'kubectl delete -f deploy --namespace=myapp-integration'
println("Integration stage finished.")
}
}
catch(Exception e) {
println("Integration stage failed.")
println("Cleaning integration environment...")
sh 'kubectl delete -f deploy --namespace=myapp-integration'
error("Exiting...")
}
}
}
stage('Production') {
withKubeConfig([credentialsId: 'jenkins-deployer-credentials', serverUrl: 'https://104.155.31.202']) {
sh 'kubectl create cm nodejs-app --from-file=src/ --namespace=myapp-production -o=yaml --dry-run > deploy/cm.yaml'
sh 'kubectl apply -f deploy/ --namespace=myapp-production'
//Gathering Node.js app's external IP address
def ip = ''
def count = 0
def countLimit = 10
//Waiting loop for IP address provisioning
println("Waiting for IP address")
while(ip=='' && count<countLimit) {
sleep 30
ip = sh script: 'kubectl get svc --namespace=myapp-production -o jsonpath="{.items[?(@.metadata.name==\'nginx-reverseproxy-service\')].status.loadBalancer.ingress[*].ip}"', returnStdout: true
ip = ip.trim()
count++
}
if(ip==''){
error("Not able to get the IP address. Aborting...")
}
else{
//Executing tests
sh "chmod +x tests/production-tests.sh && ./tests/production-tests.sh ${ip}"
}
}
}
}