forked from rh-integration/3scale-toolbox-jenkins-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
168 lines (146 loc) · 7.63 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!groovy
library identifier: '3scale-toolbox-jenkins@master',
retriever: modernSCM([$class: 'GitSCMSource',
remote: 'https://github.com/rh-integration/3scale-toolbox-jenkins.git',
traits: [[$class: 'jenkins.plugins.git.traits.BranchDiscoveryTrait']]])
def service = null
node() {
stage('Checkout Source') {
checkout scm
}
stage("Deploy API in Dev") {
// Prepare
service = toolbox.prepareThreescaleService(
openapi: [filename: "multi-environment-usecase/swagger.yaml"],
environment: [ baseSystemName: "multi_environment_usecase",
publicBasePath: "/api/",
environmentName: "dev",
publicStagingWildcardDomain: params.PUBLIC_STAGING_WILDCARD_DOMAIN != "" ? params.PUBLIC_STAGING_WILDCARD_DOMAIN : null,
publicProductionWildcardDomain: params.PUBLIC_PRODUCTION_WILDCARD_DOMAIN != "" ? params.PUBLIC_PRODUCTION_WILDCARD_DOMAIN : null,
privateBaseUrl: params.PRIVATE_BASE_URL ],
toolbox: [ openshiftProject: params.NAMESPACE,
destination: params.TARGET_INSTANCE,
image: "quay.io/redhat/3scale-toolbox:master", // TODO: remove me once the final image is released
insecure: params.DISABLE_TLS_VALIDATION == "yes",
secretName: params.SECRET_NAME],
service: [:],
applications: [
[ name: "my-test-app", description: "This is used for tests", plan: "test", account: params.DEVELOPER_ACCOUNT_ID ]
],
applicationPlans: [
[ systemName: "test", name: "Test", defaultPlan: true, published: true ]
]
)
// Import OpenAPI
service.importOpenAPI()
echo "Service with system_name ${service.environment.targetSystemName} created !"
// Create an Application Plan
service.applyApplicationPlans()
// Create an Application
service.applyApplication()
// Run integration tests
// To run the integration tests when using APIcast SaaS instances, we need
// to fetch the proxy definition to extract the staging public url
def proxy = service.readProxy("sandbox")
def userkey = service.applications[0].userkey
sh """set -e
echo "Public Staging Base URL is ${proxy.sandbox_endpoint}"
echo "userkey is ${userkey}"
curl -sfk -w "GetLocation: %{http_code}\n" -o /dev/null ${proxy.sandbox_endpoint}/api/location -H 'api-key: ${userkey}'
curl -sfk -w "GetTimeframe: %{http_code}\n" -o /dev/null ${proxy.sandbox_endpoint}/api/timeframe -H 'api-key: ${userkey}'
curl -sfk -w "GetParticipants: %{http_code}\n" -o /dev/null ${proxy.sandbox_endpoint}/api/participants -H 'api-key: ${userkey}'
"""
// Promote to production
service.promoteToProduction()
}
stage("Deploy API in Test") {
// Prepare
service = toolbox.prepareThreescaleService(
openapi: [filename: "multi-environment-usecase/swagger.yaml"],
environment: [ baseSystemName: "multi_environment_usecase",
publicBasePath: "/api/",
environmentName: "test",
publicStagingWildcardDomain: params.PUBLIC_STAGING_WILDCARD_DOMAIN != "" ? params.PUBLIC_STAGING_WILDCARD_DOMAIN : null,
publicProductionWildcardDomain: params.PUBLIC_PRODUCTION_WILDCARD_DOMAIN != "" ? params.PUBLIC_PRODUCTION_WILDCARD_DOMAIN : null,
privateBaseUrl: params.PRIVATE_BASE_URL ],
toolbox: [ openshiftProject: params.NAMESPACE,
destination: params.TARGET_INSTANCE,
image: "quay.io/redhat/3scale-toolbox:master", // TODO: remove me once the final image is released
insecure: params.DISABLE_TLS_VALIDATION == "yes",
secretName: params.SECRET_NAME],
service: [:],
applications: [
[ name: "my-test-app", description: "This is used for tests", plan: "test", account: params.DEVELOPER_ACCOUNT_ID ]
],
applicationPlans: [
[ systemName: "test", name: "Test", defaultPlan: true, published: true ]
]
)
// Import OpenAPI
service.importOpenAPI()
echo "Service with system_name ${service.environment.targetSystemName} created !"
// Create an Application Plan
service.applyApplicationPlans()
// Create an Application
service.applyApplication()
// Run integration tests
// To run the integration tests when using APIcast SaaS instances, we need
// to fetch the proxy definition to extract the staging public url
def proxy = service.readProxy("sandbox")
def userkey = service.applications[0].userkey
sh """set -e
echo "Public Staging Base URL is ${proxy.sandbox_endpoint}"
echo "userkey is ${userkey}"
curl -sfk -w "GetLocation: %{http_code}\n" -o /dev/null ${proxy.sandbox_endpoint}/api/location -H 'api-key: ${userkey}'
curl -sfk -w "GetTimeframe: %{http_code}\n" -o /dev/null ${proxy.sandbox_endpoint}/api/timeframe -H 'api-key: ${userkey}'
curl -sfk -w "GetParticipants: %{http_code}\n" -o /dev/null ${proxy.sandbox_endpoint}/api/participants -H 'api-key: ${userkey}'
"""
// Promote to production
service.promoteToProduction()
}
stage("Deploy API in Prod") {
// Prepare
service = toolbox.prepareThreescaleService(
openapi: [filename: "multi-environment-usecase/swagger.yaml"],
environment: [ baseSystemName: "multi_environment_usecase",
publicBasePath: "/api/",
environmentName: "prod",
publicStagingWildcardDomain: params.PUBLIC_STAGING_WILDCARD_DOMAIN != "" ? params.PUBLIC_STAGING_WILDCARD_DOMAIN : null,
publicProductionWildcardDomain: params.PUBLIC_PRODUCTION_WILDCARD_DOMAIN != "" ? params.PUBLIC_PRODUCTION_WILDCARD_DOMAIN : null,
privateBaseUrl: params.PRIVATE_BASE_URL ],
toolbox: [ openshiftProject: params.NAMESPACE,
destination: params.TARGET_INSTANCE,
image: "quay.io/redhat/3scale-toolbox:master", // TODO: remove me once the final image is released
insecure: params.DISABLE_TLS_VALIDATION == "yes",
secretName: params.SECRET_NAME],
service: [:],
applications: [
[ name: "my-test-app", description: "This is used for tests", plan: "test", account: params.DEVELOPER_ACCOUNT_ID ]
],
applicationPlans: [
[ systemName: "test", name: "Test", defaultPlan: true, published: true ]
]
)
// Import OpenAPI
service.importOpenAPI()
echo "Service with system_name ${service.environment.targetSystemName} created !"
// Create an Application Plan
service.applyApplicationPlans()
// Create an Application
service.applyApplication()
// Run integration tests
// To run the integration tests when using APIcast SaaS instances, we need
// to fetch the proxy definition to extract the staging public url
def proxy = service.readProxy("sandbox")
def userkey = service.applications[0].userkey
sh """set -e
echo "Public Staging Base URL is ${proxy.sandbox_endpoint}"
echo "userkey is ${userkey}"
curl -sfk -w "GetLocation: %{http_code}\n" -o /dev/null ${proxy.sandbox_endpoint}/api/location -H 'api-key: ${userkey}'
curl -sfk -w "GetTimeframe: %{http_code}\n" -o /dev/null ${proxy.sandbox_endpoint}/api/timeframe -H 'api-key: ${userkey}'
curl -sfk -w "GetParticipants: %{http_code}\n" -o /dev/null ${proxy.sandbox_endpoint}/api/participants -H 'api-key: ${userkey}'
"""
// Promote to production
service.promoteToProduction()
}
}