-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathJenkinsfile
86 lines (74 loc) · 3.55 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
#!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("Prepare") {
service = toolbox.prepareThreescaleService(
openapi: [filename: "hybrid-usecase-oidc/swagger.json"],
environment: [ baseSystemName: "hybrid_usecase_oidc",
publicBasePath: "/v1",
publicStagingWildcardDomain: params.PUBLIC_STAGING_WILDCARD_DOMAIN,
publicProductionWildcardDomain: params.PUBLIC_PRODUCTION_WILDCARD_DOMAIN,
oidcIssuerEndpoint: params.OIDC_ISSUER_ENDPOINT,
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 ],
[ systemName: "silver", name: "Silver" ],
[ systemName: "gold", name: "Gold" ],
]
)
//echo "toolbox version = " + service.toolbox.getToolboxVersion()
}
stage("Import OpenAPI") {
service.importOpenAPI()
echo "Service with system_name ${service.environment.targetSystemName} created !"
}
stage("Create an Application Plan") {
service.applyApplicationPlans()
}
stage("Create an Application") {
service.applyApplication()
}
stage("Run integration tests") {
def proxy = service.readProxy("sandbox")
def tokenEndpoint = getTokenEndpoint(params.OIDC_ISSUER_ENDPOINT)
def clientId = service.applications[0].clientId
def clientSecret = service.applications[0].clientSecret
sh """set -e
echo "token endpoint is ${tokenEndpoint}"
echo "Public Staging Base URL is ${proxy.sandbox_endpoint}"
echo "client_id=${clientId}"
echo "client_secret=${clientSecret}"
curl -sfk "${tokenEndpoint}" -d client_id="${clientId}" -d client_secret="${clientSecret}" -d scope=openid -d grant_type=client_credentials -o response.json
curl -sLfk https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 -o /tmp/jq
chmod 755 /tmp/jq
TOKEN="\$(/tmp/jq -r .access_token response.json)"
echo "Received access_token '\$TOKEN'"
curl -sfk -w "ListBeers: %{http_code}\n" -o /dev/null ${proxy.sandbox_endpoint}/v1/beer -H "Authorization: Bearer \$TOKEN"
curl -sfk -w "GetBeer: %{http_code}\n" -o /dev/null ${proxy.sandbox_endpoint}/v1/beer/Weissbier -H "Authorization: Bearer \$TOKEN"
curl -sfk -w "FindBeersByStatus: %{http_code}\n" -o /dev/null ${proxy.sandbox_endpoint}/v1/beer/findByStatus/available -H "Authorization: Bearer \$TOKEN"
"""
}
stage("Promote to production") {
service.promoteToProduction()
}
}
def getTokenEndpoint(String oidcIssuerEndpoint) {
def m = (oidcIssuerEndpoint =~ /(https?:\/\/)[^:]+:[^@]+@(.*)/)
return "${m[0][1]}${m[0][2]}/protocol/openid-connect/token"
}