forked from zowe/zowe-install-packaging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
240 lines (213 loc) · 9.65 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!groovy
/**
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright IBM Corporation 2018, 2019
*/
def isPullRequest = env.BRANCH_NAME.startsWith('PR-')
def zoweVersion = null
def opts = []
// keep last 20 builds for regular branches, no keep for pull requests
opts.push(buildDiscarder(logRotator(numToKeepStr: (isPullRequest ? '' : '20'))))
// disable concurrent build
opts.push(disableConcurrentBuilds())
// set upstream triggers
if (env.BRANCH_NAME == 'master') {
opts.push(pipelineTriggers([
upstream(threshold: 'SUCCESS', upstreamProjects: '/zlux,/API_Mediation/master,/Explorer-Data Sets/master,/Explorer-Jobs/master,/explorer-jes/master,/explorer-mvs/master,/explorer-uss/master')
]))
}
// define custom build parameters
def customParameters = []
customParameters.push(credentials(
name: 'PAX_SERVER_CREDENTIALS_ID',
description: 'The server credential used to create PAX file',
credentialType: 'com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl',
defaultValue: 'TestAdminzOSaaS2',
required: true
))
customParameters.push(string(
name: 'PAX_SERVER_IP',
description: 'The server IP used to create PAX file',
defaultValue: '172.30.0.1',
trim: true
))
customParameters.push(string(
name: 'PAX_SERVER_PORT',
description: 'The server port used to create PAX file',
defaultValue: '22',
trim: true
))
customParameters.push(string(
name: 'ARTIFACTORY_URL',
description: 'Artifactory URL',
defaultValue: 'https://gizaartifactory.jfrog.io/gizaartifactory',
trim: true,
required: true
))
customParameters.push(credentials(
name: 'ARTIFACTORY_SECRET',
description: 'Artifactory access secret',
credentialType: 'com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl',
defaultValue: 'GizaArtifactory',
required: true
))
opts.push(parameters(customParameters))
// set build properties
properties(opts)
node ('ibm-jenkins-slave-nvm-jnlp') {
currentBuild.result = 'SUCCESS'
try {
stage('checkout') {
// checkout source code
checkout scm
// check if it's pull request
echo "Current branch is ${env.BRANCH_NAME}"
if (isPullRequest) {
echo "This is a pull request"
}
}
stage('config') {
def commitHash = sh(script: 'git rev-parse --verify HEAD', returnStdout: true).trim()
sh """
sed -e 's/{BUILD_BRANCH}/${env.BRANCH_NAME}/g' \
-e 's/{BUILD_NUMBER}/${env.BUILD_NUMBER}/g' \
-e 's/{BUILD_COMMIT_HASH}/${commitHash}/g' \
-e 's/{BUILD_TIMESTAMP}/${currentBuild.startTimeInMillis}/g' \
manifest.json.template > manifest.json
"""
echo "Current manifest.json is:"
sh "cat manifest.json"
// load zowe version from manifest
zoweVersion = sh(
script: "cat manifest.json | jq -r '.version'",
returnStdout: true
).trim()
if (zoweVersion) {
echo "Packaging Zowe v${zoweVersion} started..."
} else {
error "Cannot find Zowe version"
}
// prepare JFrog CLI configurations
withCredentials([usernamePassword(credentialsId: params.ARTIFACTORY_SECRET, passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) {
sh "jfrog rt config rt-server-1 --url=${params.ARTIFACTORY_URL} --user=${USERNAME} --password=${PASSWORD}"
}
}
stage('prepare') {
// replace templates
echo 'replacing templates...'
sh "sed -e 's/{ZOWE_VERSION}/${zoweVersion}/g' artifactory-download-spec.json.template > artifactory-download-spec.json && rm artifactory-download-spec.json.template"
sh "sed -e 's/{ZOWE_VERSION}/${zoweVersion}/g' install/zowe-install.yaml.template > install/zowe-install.yaml && rm install/zowe-install.yaml.template"
echo 'preparing PAX workspace folder...'
// download artifactories
sh "echo 'Effective Artifactory download spec >>>>>>>' && cat artifactory-download-spec.json"
def downloadResult = sh(
script: "jfrog rt dl --spec=artifactory-download-spec.json",
returnStdout: true
).trim()
echo "artifactory download result:"
echo downloadResult
def downloadResultObject = readJSON(text: downloadResult)
if (downloadResultObject['status'] != 'success' ||
downloadResultObject['totals']['success'] != 9 || downloadResultObject['totals']['failure'] != 0) {
echo "status: ${downloadResultObject['status']}"
echo "success: ${downloadResultObject['totals']['success']}"
echo "failure: ${downloadResultObject['totals']['failure']}"
error "Failed on verifying download result"
} else {
echo "download result is successful as expected"
}
// prepare folder
// - pax-workspace/content holds binary files
// - pax-workspace/ascii holds ascii files and will be converted to IBM-1047 encoding
sh 'mkdir -p pax-workspace/ascii/scripts'
sh 'mkdir -p pax-workspace/ascii/install'
sh 'mkdir -p pax-workspace/ascii/files'
sh "mkdir -p pax-workspace/content/zowe-${zoweVersion}/files"
// copy from current github source
sh "cp -R files/* pax-workspace/content/zowe-${zoweVersion}/files"
sh "rsync -rv --include '*.json' --include '*.html' --include '*.jcl' --include '*.template' --exclude '*.zip' --exclude '*.png' --exclude '*.tgz' --exclude '*.tar.gz' --exclude '*.pax' --exclude '*.jar' --prune-empty-dirs --remove-source-files pax-workspace/content/zowe-${zoweVersion}/files pax-workspace/ascii"
sh 'cp manifest.json pax-workspace/ascii'
sh 'cp -R install/* pax-workspace/ascii/install'
sh 'cp -R scripts/* pax-workspace/ascii/scripts'
sh "mkdir -p pax-workspace/content/zowe-${zoweVersion}/files/scripts"
// jobs-api-server-start.sh is already in IBM-1047 encoding, no need to put in ascii folder
sh "mv pax-workspace/ascii/files/scripts/jobs-api-server-start.sh pax-workspace/content/zowe-${zoweVersion}/files/scripts/jobs-api-server-start.sh"
sh "mv pax-workspace/ascii/files/scripts/data-sets-api-server-start.sh pax-workspace/content/zowe-${zoweVersion}/files/scripts/data-sets-api-server-start.sh"
// tar ascii files
// debug purpose, list all ascii files before tar
sh 'find ./pax-workspace/ascii -print'
sh 'tar -c -f pax-workspace/ascii.tar -C pax-workspace/ ascii'
sh 'tar -c -f pax-workspace/api-mediation.tar -C pax-workspace/ mediation'
sh 'rm -fr pax-workspace/ascii'
// debug purpose, list all files in workspace
sh 'find ./pax-workspace -print'
}
stage('package') {
// scp files and ssh to z/OS to pax workspace
echo "creating pax file from workspace..."
timeout(time: 30, unit: 'MINUTES') {
createPaxWithPort('zowe-install-packaging', "zowe.pax",
params.PAX_SERVER_IP, params.PAX_SERVER_PORT, params.PAX_SERVER_CREDENTIALS_ID,
'./pax-workspace', '/zaas1/buildWorkspace', '-x os390',
['ZOWE_VERSION':zoweVersion])
}
}
stage('publish') {
echo 'publishing pax file to artifactory...'
def releaseIdentifier = getReleaseIdentifier()
def buildIdentifier = getBuildIdentifier(true, '__EXCLUDE__', true)
def buildName = env.JOB_NAME.replace('/', ' :: ')
echo "Artifactory build name/number: ${buildName}/${env.BUILD_NUMBER}"
// prepare build info
sh "jfrog rt bc '${buildName}' ${env.BUILD_NUMBER}"
// attach git information to build info
sh "jfrog rt bag '${buildName}' ${env.BUILD_NUMBER} ."
// upload and attach to build info
def uploadResult = sh(
script: "jfrog rt u 'pax-workspace/zowe.pax' 'libs-snapshot-local/com/project/zowe/${zoweVersion}-${releaseIdentifier}/zowe-${zoweVersion}-${buildIdentifier}.pax' --build-name=\"${buildName}\" --build-number=${env.BUILD_NUMBER} --flat",
returnStdout: true
).trim()
echo "artifactory upload result:"
echo uploadResult
def uploadResultObject = readJSON(text: uploadResult)
if (uploadResultObject['status'] != 'success' ||
uploadResultObject['totals']['success'] != 1 || uploadResultObject['totals']['failure'] != 0) {
error "Failed on verifying upload result"
} else {
echo "upload result is successful as expected"
}
// add environment variables to build info
sh "jfrog rt bce '${buildName}' ${env.BUILD_NUMBER}"
// publish build info
sh "jfrog rt bp '${buildName}' ${env.BUILD_NUMBER} --build-url=${env.BUILD_URL}"
}
stage('done') {
// send out notification
emailext body: "Job \"${env.JOB_NAME}\" build #${env.BUILD_NUMBER} success.\n\nCheck detail: ${env.BUILD_URL}" ,
subject: "[Jenkins] Job \"${env.JOB_NAME}\" build #${env.BUILD_NUMBER} success",
recipientProviders: [
[$class: 'RequesterRecipientProvider'],
[$class: 'CulpritsRecipientProvider'],
[$class: 'DevelopersRecipientProvider'],
[$class: 'UpstreamComitterRecipientProvider']
]
}
} catch (err) {
currentBuild.result = 'FAILURE'
// catch all failures to send out notification
emailext body: "Job \"${env.JOB_NAME}\" build #${env.BUILD_NUMBER} failed.\n\nError: ${err}\n\nCheck detail: ${env.BUILD_URL}" ,
subject: "[Jenkins] Job \"${env.JOB_NAME}\" build #${env.BUILD_NUMBER} failed",
recipientProviders: [
[$class: 'RequesterRecipientProvider'],
[$class: 'CulpritsRecipientProvider'],
[$class: 'DevelopersRecipientProvider'],
[$class: 'UpstreamComitterRecipientProvider']
]
throw err
}
}