-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile.publish
151 lines (129 loc) · 5.24 KB
/
Jenkinsfile.publish
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
#!/usr/bin/env groovy
@Library('tkutils')
import static tk.jenkins.slack.SlackNotify.notifySlack
import tk.jenkins.common.*
def podLabel = UUID.randomUUID().toString()
def deployWidgets = JobParameter.getBoolean(this, 'deployWidgets', false)
def deploySSE = JobParameter.getBoolean(this, 'deploySSE', false)
def deployGateway = JobParameter.getBoolean(this, 'deployGateway', false)
def widgetNames = JobParameter.get(this, 'widgetNames', 'payment-widget,saved-cards-widget')
def appName = JobParameter.get(this, 'appName', 'osf-payment-sse')
def gatewayName = JobParameter.get(this, 'gatewayName', 'payment-gateway')
def settingsPayload = JobParameter.get(this, 'settingsPayload', 'packages/payment-gateway/settings.json')
def gitBranch = 'unknown'
podTemplate(
label: podLabel,
yaml: PodSecurityContext.ROOT,
containers: [
containerTemplate(
name: 'node',
image: 'node:10.18.0',
alwaysPullImage: true,
ttyEnabled: true,
command: 'cat',
workingDir: '/home/jenkins/agent',
resourceRequestCpu: '500m',
resourceRequestMemory: '5120Mi',
resourceLimitMemory: '5120Mi',
)
],
volumes: [
secretVolume(mountPath: '/secrets', secretName: 'jenkins-service-account')
]
)
{
node(podLabel) {
try
{
currentBuild.result = 'SUCCESS'
gitBranch = GitHelper.getCurrentBranch(this)
print "checking out '${gitBranch}' branch..."
withCredentials([
usernamePassword(
credentialsId: 'isv_occ_sse',
usernameVariable: 'url',
passwordVariable: 'occ_key'),
usernamePassword(
credentialsId: 'isv_occ_widget',
usernameVariable: 'occ_user',
passwordVariable: 'occ_pwd')]) {
stage('checkout') {
checkout scm
}
stage('install') {
container('node') {
sh 'yarn install'
}
}
stage('build') {
container('node') {
sh 'yarn build'
}
}
stage('build:prod') {
container('node') {
dir('packages/server-extension') {
sh 'yarn build:prod'
}
dir('packages/payment-widget') {
sh 'yarn build:prod'
}
dir('packages/saved-cards-widget') {
sh 'yarn build:prod'
}
}
}
stage('package and upload application') {
if (deploySSE)
{
container('node') {
sh "yarn occ package-app ${appName}"
sh "yarn occ upload-app -u ${url} -k ${occ_key} ${appName}"
}
} else {
echo 'Skip server-side extension deploy'
}
}
stage('package and upload widget') {
if (deployWidgets)
{
container('node') {
widgetNames.split(',').each { widget ->
def widgetId = sh (
returnStdout: true,
script: """yarn occ find-extension-id -u ${url} -k ${occ_key} ${widget} | awk 'BEGIN{ RS = ""; FS = "\\n" } {print \$5; exit}'""").trim()
sh "yarn occ deactivate-extension -u ${url} -k ${occ_key} -e ${widgetId} ${widget}"
sh "yarn occ upload-extension -x html-reports,widget/isv-occ-payment/js/__tests__,widget/saved-cards/js/__tests__ -u ${url} -k ${occ_key} ${widget}"
}
}
} else {
echo 'Skip widgets deploy'
}
}
stage('package and upload gateway settings') {
if (deployGateway)
{
container('node') {
def gatewayId = sh (
returnStdout: true,
script: """yarn occ find-extension-id -u ${url} -k ${occ_key} ${gatewayName} | awk 'BEGIN{ RS = ""; FS = "\\n" } {print \$5; exit}'""").trim()
sh "yarn occ deactivate-extension -u ${url} -k ${occ_key} -e ${gatewayId} ${gatewayName}"
sh "yarn occ package-extension ${gatewayName}"
sh "yarn occ upload-extension -u ${url} -k ${occ_key} ${gatewayName}"
stage('set settings') {
sh "yarn occ settings:set -u ${url} -k ${occ_key} isv-occ-gateway '${settingsPayload}'"
}
}
} else {
echo 'Skip payment gateway deploy'
}
}
} // withCredentials
} catch (any) {
currentBuild.result = 'FAILURE'
throw any
} finally {
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: ''])
notifySlack(this, "cybersource-jenkins", false)
}
}}