forked from IBM/dbb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbbBuild.sh
executable file
·542 lines (490 loc) · 18.8 KB
/
dbbBuild.sh
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
#!/bin/env bash
#
#===================================================================================
# NAME: dbbBuild.sh
#
# DESCRIPTION: The purpose of this script is to perform a DBB Build from within
# a Pipeline.
#
#
# SYNTAX: See Help() Section Below
#
# OPTIONS: See Help() Section Below
#
# RETURNS:
#
# rc - Return Code
#
# RETURN CODES:
#
# 0 - Successful
# 4 - Warning message(s) issued. See Console messages.
# 8 - Error encountered. See Console messages.
#
# NOTE(S):
#
# 1. Review the pipeline backend configuration file
# (pipelineBackend.config) which sets general as well as
# Dependency Based Build values that must be supplied.
#
# 2. This script contains processing logic that is specific to the branch being
# processed for a pre-defined set of branch names. This processing will
# determine the following build options values:
#
# Build Type - The type of build to perform. Refer to zAppBuild
# build.groovy for more information.
# HLQ - High Level data set qualifier used DBB build output.
#
# Review the "Build Type Customization" section below for additional information.
#
# 3. This script supports Dependency Base Build V2.x and above.
#
# Maintenance Log
#
# Date Who Vers Description
# ---------- --- ----- --------------------------------------------------------------
# 2023/07/27 TLD 1.0.0 Initial Release
# 2023/08/28 D 1.1.0 Introducing pipelineConfig and dbbBuildUtils.sh
#===================================================================================
Help() {
echo $PGM" - Invoke DBB Build ("$PGMVERS") "
echo " "
echo "Description: The purpose of this script is to perform "
echo "invoke the central build framework. "
echo " "
echo "Syntax: "
echo " "
echo " "$PGM" [Options] "
echo " "
echo "Options: "
echo " "
echo " -h - Display this Help. "
echo " "
echo " -w <workspace> - Directory Path to a unique "
echo " working directory "
echo " Either an absolute path "
echo " or relative path. "
echo " If a relative path is provided, "
echo " buildRootDir and the workspace "
echo " path are combined "
echo " Default=None, Required. "
echo " "
echo " Ex: MortgageApplication/main/build-1 "
echo " "
echo " "
echo " -a <Application> - Folder name to the DBB Main "
echo " Application Source located under "
echo " <Workspace>/<Application>. "
echo " "
echo " Ex: MortgageApplication "
echo " "
echo " "
echo " -b <Branch> - Name of the Branch to compute "
echo " the build dataset qualifier. "
echo " Default=None, Required. "
echo " "
echo " Ex: main "
echo " "
echo " "
echo " -p <pipelineType> - Type of the pipeline to "
echo " control if this builds with "
echo " optimize or test options "
echo " also impacting HLQ "
echo " Default=build, Required. "
echo " Accepted values: "
echo " build - "
echo " perform build with TEST options "
echo " release - "
echo " perform build with options for "
echo " performance optimized "
echo " executables "
echo " preview - "
echo " perform build zAppBuild option "
echo " --preview "
echo " "
echo " Ex: build "
echo " "
echo " -q - (Optional) dataset qualifier "
echo " for build datasets "
echo " to override the configured "
echo " dataset qualifer in "
echo " pipelineBackend.config "
echo " Ex: USER.APP "
echo " "
echo " -bc - (Optional) zAppBuild build "
echo " options to override "
echo " the computed build configuration "
echo " Ex: --fullBuild "
echo " "
echo " -v - (Optional) Verbose tracing "
echo " flag for zAppBuild "
echo " "
echo " "
exit 0
}
#
# Build Type Customization
# Configuration file leveraged by the backend scripts
# Either an absolute path or a relative path to the current working directory
SCRIPT_HOME="`dirname "$0"`"
pipelineConfiguration="${SCRIPT_HOME}/pipelineBackend.config"
buildUtilities="${SCRIPT_HOME}/utilities/dbbBuildUtils.sh"
# Customization - End
#
# Internal Variables
#set -x # Uncomment to enable shell script debug
#export BASH_XTRACEFD=1 # Write set -x trace to file descriptor
PGM=$(basename "$0")
PGMVERS="1.10"
USER=$USER
SYS=$(uname -Ia)
rc=0
ERRMSG=""
# Initialized option variables passed to this script
Workspace=""
App=""
Branch=""
PipelineType=""
HELP=$1
# Local Variables
# TLD: Always a good idea to initialize any local varables
AppDir="" # Derived Application Directory
HLQ="" # Derived High Level Qualifier
HLQPrefix="" # Prefix of HLQ, either specified via the cli option -q or via configuration file
Type="" # Derived Build Type
baselineRef="" # baselineReference that is computed by utilities/dbbBuildUtils.sh
propOverrides="" # Override of default build parameters for zAppBuild
# computed by utilities/dbbBuildUtils.sh
outDir="" # Computed output directory to store build protocols
nestedApplicationFolder="" # Flag to understand a nested repository
LastBuildLog=""
buildlistsize=0
DBBLogger=""
zAppBuildVerbose=""
HELP=$1
if [ "$HELP" = "?" ]; then
Help
fi
# Validate Shell environment
currentShell=$(ps -p $$ | grep bash)
if [ -z "${currentShell}" ]; then
rc=8
ERRMSG=$PGM": [ERROR] The scripts are designed to run in bash. You are running a different shell. rc=${rc}. \n. $(ps -p $$)."
echo $ERRMSG
fi
#
if [ $rc -eq 0 ]; then
echo $PGM": [INFO] DBB Build Wrapper. Version="$PGMVERS
fi
# Read and import pipeline configuration
if [ $rc -eq 0 ]; then
if [ ! -f "${pipelineConfiguration}" ]; then
rc=8
ERRMSG=$PGM": [ERROR] Pipeline Configuration File (${pipelineConfiguration}) was not found. rc="$rc
echo $ERRMSG
else
source $pipelineConfiguration
fi
# Read and import utilities
if [ ! -f "${buildUtilities}" ]; then
rc=8
ERRMSG=$PGM": [ERROR] DBB-Build internal utilities (${buildUtilities}) was not found. rc="$rc
echo $ERRMSG
else
source $buildUtilities
fi
#
# Get Options
if [ $rc -eq 0 ]; then
while getopts "h:w:a:b:q:p:t:v" opt; do
case $opt in
h)
Help
;;
w)
argument="$OPTARG"
nextchar="$(expr substr $argument 1 1)"
if [ -z "$argument" ] || [ "$nextchar" = "-" ]; then
rc=4
ERRMSG=$PGM": [WARNING] Build Workspace Folder Name is required. rc="$rc
echo $ERRMSG
break
fi
Workspace="$argument"
;;
a)
argument="$OPTARG"
nextchar="$(expr substr $argument 1 1)"
if [ -z "$argument" ] || [ "$nextchar" = "-" ]; then
rc=4
ERRMSG=$PGM": [WARNING] Application Folder Name is required. rc="$rc
echo $ERRMSG
break
fi
App="$argument"
;;
b)
argument="$OPTARG"
nextchar="$(expr substr $argument 1 1)"
if [ -z "$argument" ] || [ "$nextchar" = "-" ]; then
rc=4
ERRMSG=$PGM": [WARNING] Branch Name is required. rc="$rc
echo $ERRMSG
break
fi
Branch="$argument"
;;
t)
argument="$OPTARG"
# stop if the argument is -[a-z]
check="^-[a-z]"
if [ -z "$argument" ] || [[ "$argument" =~ $check ]]; then
rc=4
ERRMSG=$PGM": [WARNING] Build type/configuration is required. rc="$rc
echo $ERRMSG
break
fi
Type="$argument"
;;
p)
argument="$OPTARG"
nextchar="$(expr substr $argument 1 1)"
if [ -z "$argument" ] || [ "$nextchar" = "-" ]; then
rc=4
INFO=$PGM": [INFO] No Pipeline type specified. rc="$rc
echo $INFO
break
fi
PipelineType="$argument"
;;
v)
# set the pipeline flag to turn on zAppBuild tracing
Verbose=1
;;
q)
# dataset qualifier
argument="$OPTARG"
nextchar="$(expr substr $argument 1 1)"
if [ -z "$argument" ] || [ "$nextchar" = "-" ]; then
rc=4
INFO=$PGM": [WARNING] Dataset qualifier is required (-q). rc="$rc
echo $INFO
break
fi
HLQPrefix="$argument"
;;
\?)
Help
rc=1
break
;;
:)
rc=4
ERRMSG=$PGM": [WARNING] Option -$OPTARG requires an argument. rc="$rc
echo $ERRMSG
break
;;
esac
done
fi
fi
#
# Validate Options
validateOptions() {
if [ -z "${Workspace}" ]; then
rc=8
ERRMSG=$PGM": [ERROR] Unique Workspace parameter (-w) is required. rc="$rc
echo $ERRMSG
else
# Compute the outDir parameter
outDir=$(getLogDir)
if [ ! -d "$(getWorkDirectory)" ]; then
rc=8
ERRMSG=$PGM": [ERROR] Workspace Directory ($(getWorkDirectory)) was not found. rc="$rc
echo $ERRMSG
fi
fi
if [ -z "${App}" ]; then
rc=8
ERRMSG=$PGM": [ERROR] Application parameter (-a) is required. rc="$rc
echo $ERRMSG
else
AppDir=$(getApplicationDir)
# Check if application directory contains
if [ -d "${AppDir}/${App}" ]; then
echo $PGM": [INFO] Detected the application respository (${App}) within the git repository layout structure."
echo $PGM": [INFO] Assuming this as the new application location."
AppDir="${AppDir}/${App}"
nestedApplicationFolder="true"
fi
if [ ! -d "${AppDir}" ]; then
rc=8
ERRMSG=$PGM": [ERROR] Application Directory (${AppDir}) was not found. rc="$rc
echo $ERRMSG
fi
fi
if [ -z "${Branch}" ]; then
rc=8
ERRMSG=$PGM": [ERROR] Branch Name parameter (-b) is required. rc="$rc
echo $ERRMSG
fi
tmp1=$(echo $PipelineType | tr '[:upper:]' '[:lower:]')
case $tmp1 in
"build") ;;
"release") ;;
"preview") ;;
*)
rc=0
PipelineType="build"
ERRMSG=$PGM": [INFO] Set default Pipeline Type : ${PipelineType} ."
echo $ERRMSG
;;
esac
if [ -z "${dbbMetadataStoreJdbcId}" ]; then
echo $PGM": [WARNING] Db2 JDBC User not set. It is recommended to use Db2 for the DBB Metadatastore."
fi
if [ -z "${dbbMetadataStoreJdbcPwdFile}" ]; then
echo $PGM": [WARNING] Db2 JDBC Password file not set. It is recommended to use Db2 for the DBB Metadatastore."
else
if [ ! -f "${dbbMetadataStoreJdbcPwdFile}" ]; then
rc=8
ERRMSG=$PGM": [ERROR] DBB database password file (${dbbMetadataStoreJdbcPwdFile}) was not found. rc="$rc
echo $ERRMSG
fi
fi
BuildGroovy="${zAppBuild}/build.groovy"
if [ ! -f "${BuildGroovy}" ]; then
rc=8
ERRMSG=$PGM": [ERROR] Unable to locate ${BuildGroovy}. rc="$rc
echo $ERRMSG
fi
#
# Check to see if debug options were requested and set up switches
# to enable.
if [ ${Verbose} -eq 1 ]; then
zAppBuildVerbose="--verbose"
fi
if [ ${LoggerConfig} -eq 1 ]; then
DBBLogger="-classpath ${AppDir}/application-conf"
fi
}
# Call validate Options
if [ $rc -eq 0 ]; then
validateOptions
fi
# Call utilities to compute build type based on pipeline
if [ $rc -eq 0 ]; then
##DEBUG## echo $PGM": [DEBUG] **************************************************************"
##DEBUG## echo $PGM": [DEBUG] ** Started - ComputeBuildConfiguration"
# Note : Error-handling within the utlities
computeBuildConfiguration
fi
# Validate hlq length
if [ $rc -eq 0 ]; then
if [ ${#HLQ} -gt 35 ]; then
rc=8
ERRMSG=$PGM": [ERROR] High-Level Qualifier (${HLQ}) exceeds maximum length of 35. rc="$rc
echo $ERRMSG
fi
fi
# Ready to go TLD: Suggest in the section to echo as much as possible
if [ $rc -eq 0 ]; then
echo $PGM": [INFO] **************************************************************"
echo $PGM": [INFO] ** Started - DBB Build on HOST/USER: ${SYS}/${USER}"
echo $PGM": [INFO] ** Workspace:" $(getWorkDirectory)
echo $PGM": [INFO] ** Application:" ${App}
echo $PGM": [INFO] ** Branch:" ${Branch}
echo $PGM": [INFO] ** Build Type:" ${Type}
if [ ! -z "${propOverrides}" ]; then
echo $PGM": [INFO] ** Property Override :" ${propOverrides}
fi
echo $PGM": [INFO] ** HLQ:" ${HLQ}
echo $PGM": [INFO] ** AppDir:" ${AppDir}
echo $PGM": [INFO] ** LogDir:" ${outDir}
echo $PGM": [INFO] ** zAppBuild Path:" ${zAppBuild}
echo $PGM": [INFO] ** DBB_HOME:" ${DBB_HOME}
echo $PGM": [INFO] ** DBB JDBC USER:" ${dbbMetadataStoreJdbcId}
echo $PGM": [INFO] ** DBB JDBC Pwd File:" ${dbbMetadataStoreJdbcPwdFile}
if [ ! -z "${dbbMetadataStoreJdbcUrl}" ]; then
echo $PGM": [INFO] ** DBB JDBC Url :" ${dbbMetadataStoreJdbcUrl}
fi
if [ ${Verbose} -eq 1 ]; then
echo $PGM": [INFO] ** Verbose :" ${zAppBuildVerbose}
else
echo $PGM": [INFO] ** Verbose : No"
fi
if [ ${LoggerConfig} -eq 1 ]; then
echo $PGM": [INFO] ** DBB Logger:" ${DBBLogger}
else
echo $PGM": [INFO] ** DBB Logger: No"
fi
echo $PGM": [INFO] **************************************************************"
echo ""
fi
# TLD - This is where I left off. The below was taken directly from the Azure Script copy.
# More updates will need to be performed to support DBB 2.x. The following code segments
# where derived directly from the Azure version of this script.
#
# Invoke the DBB Build
if [ $rc -eq 0 ]; then
echo $PGM": [INFO] Invoking the zAppBuild Build Framework."
# Assemble build command
CMD="$DBB_HOME/bin/groovyz ${DBBLogger} ${BuildGroovy} --workspace $(getWorkDirectory) --application ${App} --outDir ${outDir} --hlq ${HLQ} ${zAppBuildVerbose} --logEncoding UTF-8"
if [ ! -z "${dbbMetadataStoreJdbcId}" ]; then
CMD="${CMD} --id ${dbbMetadataStoreJdbcId}" # Appending JDBC User Id if defined
fi
if [ ! -z "${dbbMetadataStoreJdbcPwdFile}" ]; then
CMD="${CMD} --pwFile ${dbbMetadataStoreJdbcPwdFile}" # Appending JDBC Password file if defined
fi
if [ ! -z "${dbbMetadataStoreJdbcUrl}" ]; then
CMD="${CMD} --url ${dbbMetadataStoreJdbcUrl}" # Appending JDBC URL if defined
fi
if [ ! -z "${zAppBuildPropFiles}" ]; then
CMD="${CMD} --propFiles ${zAppBuildPropFiles}" # Appending propFiles if defined
fi
if [ ! -z "${propOverrides}" ]; then
CMD="${CMD} --propOverwrites ${propOverrides}" # Appending propOverrides if defined
fi
CMD="${CMD} ${Type}" # Append zAppBuild Build Type
echo $PGM": [INFO] ${CMD}"
${CMD} #TLD: I commented this out for testing purposed
rc=$?
#exit 0
if [ $rc -eq 0 ]; then
## Except for the reset mode, check for "nothing to build" condition and throw an error to stop pipeline
if [ "$Type" != "--reset" ]; then
# Locate the most recent Build Log Directory within outDir. The Build Log Directories are Time Stamped.
# Therefore, the last directory entry will be the most recent Build Log. The directory will always be
# be created by DBB, but "buildList.txt" may not. If not created, array will will be blank.
array=$(find ${outDir} -name "buildList.txt")
for log in ${array[@]}; do
LastBuildLog=${log}
echo $PGM": [INFO] LastBuildLog = ${LastBuildLog}"
done
# If "buildList.txt" was found in the last Build Log Directory, determine the character count.
# wc -c will return the two values; Character Count and Log File Path. Parse out the Character Count.
if [ -z ${LastBuildLog} ]; then
buildlistsize=0
else
set $(wc -c <${LastBuildLog})
buildlistsize=$1
fi
if [ $buildlistsize = 0 ]; then
rc=4
ERRMSG=$PGM": [WARNING] DBB Build Error. No source changes detected. rc="$rc
echo $ERRMSG
else
ERRMSG=$PGM": [INFO] DBB Build Complete. rc="$rc
echo $ERRMSG
fi
else
ERRMSG=$PGM": [INFO] DBB Reset Complete. rc="$rc
echo $ERRMSG
fi
else
ERRMSG=$PGM": [ERROR] DBB Build Error. Check Console and Build Log for details. rc="$rc
echo $ERRMSG
rc=8
fi
fi
exit $rc