/
pipeline.groovy
105 lines (105 loc) · 3.46 KB
/
pipeline.groovy
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
node {
withCredentials([string(credentialsId: 'ORACLE_BEARER', variable: 'BEARER')]) {
def WORKSPACE
stage('Prepare') {
WORKSPACE = pwd()
echo "where am I ... ${WORKSPACE}"
echo "which version to process ... ${version}"
sh "rm -f ${WORKSPACE}/*.json"
sh "curl -O https://raw.githubusercontent.com/michaelhuettermann/sandbox/master/all/src/main/resources/jenkins/oracle-cloud/new-service.json"
sh "curl -O https://raw.githubusercontent.com/michaelhuettermann/sandbox/master/all/src/main/resources/jenkins/oracle-cloud/create-deployment.json"
sh "sed -i 's/VERSION/${version}/g' ${WORKSPACE}/new-service.json"
sh "sed -i 's/VERSION/${version}/g' ${WORKSPACE}/create-deployment.json"
}
stage('Deployment Stop') {
sh '''
#!/bin/bash
set +x
export PYTHONIOENCODING=utf8
echo -ne "Stopping deployment "
curl -sk -X "POST" -H "Authorization: Bearer ${BEARER}" "https://${CLOUDIP}/api/v2/deployments/meow-deploy/stop"
result=$(curl -sk -X 'GET' -H "Authorization: Bearer ${BEARER}" https://${CLOUDIP}/api/v2/deployments/meow-deploy)
if [[ "$result" == *"errors"* ]]; then
echo "No deployment found ... !"
else
echo "Deployment found ..."
for (( ; ; ))
do
result=$(curl -sk -X 'GET' -H "Authorization: Bearer ${BEARER}" https://${CLOUDIP}/api/v2/deployments/meow-deploy | \
python -c "import sys, json; print(json.load(sys.stdin)['deployment']['current_state'])")
if [ "$result" == "0" ]; then
sleep 10
echo "Deployment stopped!"
break
else
echo "."
sleep 2
continue
fi
done
fi
'''
}
stage('Deployment Delete') {
sh '''
#!/bin/bash
set +x
echo "Delete deployment ..."
curl -sk -X "DELETE" -H "Authorization: Bearer ${BEARER}" "https://${CLOUDIP}/api/v2/deployments/meow-deploy"
sleep 5
'''
}
stage('Service Delete') {
sh '''
#!/bin/bash
set +x
echo "Delete service ..."
curl -sk -X "DELETE" -H "Authorization: Bearer ${BEARER}" "https://${CLOUDIP}/api/v2/services/meow"
sleep 5
'''
}
stage('Image Delete') {
sh '''
#!/bin/bash
set +x
echo "Delete image ..."
curl -sk -X "DELETE" -H "Authorization: Bearer ${BEARER}" "https://${CLOUDIP}/api/v2/images/iad.ocir.io/mh/michaelhuettermann/alpine-tomcat7:${version}/hosts/ebff015f-70c2-6652-7e17-cb9d92ff949c"
sleep 5
'''
}
stage('Image Pull') {
sh '''
#!/bin/bash
set +x
echo "Pull image ..."
curl -sk -X "POST" -H "Authorization: Bearer ${BEARER}" "https://${CLOUDIP}/api/v2/images/iad.ocir.io/mh/michaelhuettermann/alpine-tomcat7:${version}/hosts/ebff015f-70c2-6652-7e17-cb9d92ff949c/pull"
sleep 5
'''
}
stage('Service Create') {
echo "workspace = ${WORKSPACE}"
sh '''
#!/bin/bash
set +x
echo "Create service ..."
curl -ski -X "POST" -H "Authorization: Bearer ${BEARER}" "https://${CLOUDIP}/api/v2/services/" \
--data "@${WORKSPACE}/new-service.json"
sleep 5
'''
}
stage('Deployment Create') {
echo "workspace = ${WORKSPACE}"
timeout(time:5, unit:'MINUTES') {
input message:"Really sure to go the very last mile, with version ${version}?"
}
sh '''
#!/bin/bash
set +x
echo "Create deployment ..."
curl -ski -X "POST" -H "Authorization: Bearer ${BEARER}" "https://${CLOUDIP}/api/v2/deployments/" \
--data "@${WORKSPACE}/create-deployment.json"
sleep 5
'''
}
}
}