This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathsyndesis-pipeline.groovy
109 lines (98 loc) · 4.22 KB
/
syndesis-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
106
107
108
109
def exportHost = params.EXPORT_HOSTNAME
def importHost = params.IMPORT_HOSTNAME
def exportTagName = params.EXPORT_TAG_NAME
def importTagName = params.IMPORT_TAG_NAME
def exportToken = params.EXPORT_SECRET_TOKEN
def importToken = params.IMPORT_SECRET_TOKEN
def doImport = false
def exportFile = ''
def importResponseFile = ''
pipeline {
agent any
stages {
stage('Prepare') {
steps {
script {
// create working directory
workDir = "work-${env.BUILD_NUMBER}"
touch "${workDir}/.keep"
}
sh "mkdir -p ${workDir}"
echo "Created working directory ${workDir}"
script {
exportFile = "${workDir}/export.zip"
importResponseFile = "${workDir}/import_response.json"
}
}
}
stage('Export') {
steps {
// Export integrations from source host
// call GET from https://${importHost}/api/v1/public/integrations/${tagName}/export.zip
sh "curl -v -k -L -H 'Content-Type: application/json' -H 'SYNDESIS-XSRF-TOKEN: awesome' -H 'Authorization: Bearer ${exportToken}' https://${exportHost}/api/v1/public/integrations/${exportTagName}/export.zip -o ${exportFile}"
script {
def exportZips = findFiles(glob: exportFile)
if (exportZips != null && exportZips.length == 1) {
echo "Exported integrations from ${exportHost} with tag ${exportTagName}"
} else {
echo "No integrations to export from ${exportHost} with tag ${exportTagName}"
}
}
}
}
stage('Confirm') {
steps {
// Confirm file exported and prompt to import
script {
if (fileExists(exportFile)) {
input message: "Press Continue to import integrations in to ${importHost}", ok: 'Continue'
doImport = true
}
}
}
}
stage('Import') {
steps {
script {
if (doImport) {
// Import integration into target host
// call POST to https://${exportHost}/api/v1/public/integrations/
sh "curl -v -k -L -H 'Content-Type: multipart/form-data' -H 'SYNDESIS-XSRF-TOKEN: awesome' -H 'Authorization: Bearer ${importToken}' https://${importHost}/api/v1/public/integrations -F data=@${exportFile} -F environment=${importTagName} -o ${importResponseFile}"
echo "Imported integrations into ${importHost} with tag ${importTagName}"
} else {
echo 'No integrations to import!'
}
}
}
}
stage('Deploy') {
steps {
script {
if (fileExists(importResponseFile)) {
// read the response json
def response = readJSON file: importResponseFile
response.results.findAll { it.containsKey("flows") } .each { integration ->
// deploy the integration
def intId = integration.id
echo "Deploying integration ${integration.name} id:${intId} ..."
sh "curl -v -k -L -H 'Content-Type: application/json' -H 'SYNDESIS-XSRF-TOKEN: awesome' -H 'Authorization: Bearer ${exportToken}' https://${exportHost}/api/v1/public/integrations/${intId}/deployments -X POST -o ${workDir}/deploy_response_${intId}.json"
echo "Deployed ${intId}"
}
}
}
}
}
}
post {
always {
// archive all files from the build
archiveArtifacts "${workDir}/**"
}
cleanup {
// delete work directory
dir(workDir) {
deleteDir()
}
}
}
}