forked from SAP/apibusinesshub-integration-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
57 lines (54 loc) · 1.94 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
pipeline {
agent any
//Configure the following environment variables before executing the Jenkins Job
environment {
IntegrationFlowID = "IntegrationFlow1"
CPIHost = "${env.CPI_HOST}"
CPIOAuthHost = "${env.CPI_OAUTH_HOST}"
CPIOAuthCredentials = "${env.CPI_OAUTH_CRED}"
}
stages {
stage('Generate oauth bearer token') {
steps {
script {
//get oauth token for Cloud Integration
println("requesting oauth token");
try{
def getTokenResp = httpRequest acceptType: 'APPLICATION_JSON',
authentication: env.CPIOAuthCredentials,
contentType: 'APPLICATION_JSON',
httpMode: 'POST',
responseHandle: 'LEAVE_OPEN',
timeout: 30,
url: 'https://' + env.CPIOAuthHost + '/oauth/token?grant_type=client_credentials';
def jsonObjToken = readJSON text: getTokenResp.content
def token = "Bearer " + jsonObjToken.access_token
env.token = token
getTokenResp.close();
} catch (Exception e) {
error("Requesting oauth token for Cloud Integration failed:\n${e}")
}
}
}
}
stage('Undeploy integration artefact') {
steps {
script {
//undeploy integration flow as specified in the configuration
println("Undeploying integration flow.");
try{
def undeployResp = httpRequest httpMode: 'DELETE',
customHeaders: [
[maskValue: false, name: 'Authorization', value: env.token]
],
ignoreSslErrors: true,
timeout: 30,
url: 'https://' + env.CPIHost + '/api/v1/IntegrationRuntimeArtifacts(\'' + env.IntegrationFlowID + '\')';
} catch (Exception e) {
error("Undeploying the integration flow failed:\n${e}")
}
}
}
}
}
}