Produced by Araxis Merge on 4/18/2019 5:55:29 PM Eastern Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
# | Location | File | Last Modified |
---|---|---|---|
1 | MCCF_EDI_TAS_TASCore v2.0_Build_10.zip\MCCF_EDI_TAS_DevOps\mccf_devops | nginx.jenkinsfile | Wed Apr 3 02:27:32 2019 UTC |
2 | MCCF_EDI_TAS_TASCore v2.0_Build_10.zip\MCCF_EDI_TAS_DevOps\mccf_devops | nginx.jenkinsfile | Tue Apr 16 15:23:36 2019 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 1458 |
Changed | 1 | 2 |
Inserted | 0 | 0 |
Removed | 0 | 0 |
Whitespace | |
---|---|
Character case | Differences in character case are significant |
Line endings | Differences in line endings (CR and LF characters) are ignored |
CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
1 | pipeline() { | |
2 | environm ent{ | |
3 | def pr oductAcron ym="TAS_GA TEWAY" | |
4 | def pr oductMajor Version='0 1' | |
5 | def pr oductMinor Version='0 0' | |
6 | def pr oductRev=" ${BUILD_NU MBER}" | |
7 | def pa ckageVersi on="${prod uctAcronym }.${produc tMajorVers ion}.${pro ductMinorV ersion}.${ productRev }" | |
8 | def hc Room = '32 42078' | |
9 | def da teString = new Date( currentBui ld.startTi meInMillis ).format(' yyyyMMdd_H Hmmss') | |
10 | def AR TIFACT_LOC ATION = "$ {WORKSPACE }/artifact s/${dateSt ring}" | |
11 | def DI ST_OUTPUT_ FILENAME=' ' | |
12 | def DI ST_OUTPUT_ FILE='' | |
13 | def la stCommitID ='' | |
14 | def pa ckageName= '' | |
15 | def WE B_BASEDIR= "/var/www/ html" | |
16 | def ST AGING_DIR= "${WEB_BAS EDIR}/dev/ tas" | |
17 | def ST AGING_URL= "${STAGE_U RL}" | |
18 | def mc cf_git_rep o="https:/ /bitbucket .org/halfa ker/mccf_d evops" | |
19 | def bu ildResultU UID='' | |
20 | def TA SWorkspace ="${WORKSP ACE}" | |
21 | def TA S_GATEWAY= "MCCF_EDI_ TAS_Gatewa y" | |
22 | def pr oductBuild Dir="${TAS _GATEWAY}" | |
23 | def TA S_GATEWAY_ BUILD_ARTI FACTS="Bui ld_Artifac ts" | |
24 | def la stGitTag=' ' | |
25 | def sc mtool="/op t/ibm/team concert/6. 0.1/jazz/s cmtools/ec lipse/scm. sh" | |
26 | def lo calTMP="${ WORKSPACE} /tmp" | |
27 | def br anch_name= '' | |
28 | def pr ojectname= "tasGatewa y" | |
29 | def do ckerfile=" Dockerfile .nginx" | |
30 | de f gatewayD krRepo="ta s/gateway" | |
31 | def ga tewayTAG=" tas/gatewa y:${produc tMajorVers ion}.${pro ductMinorV ersion}.${ productRev }" | |
32 | } | |
33 | ||
34 | agent an y | |
35 | options { timestam ps() } | |
36 | stages{ | |
37 | stage( 'Prepare w orkspace w ith source code') { | |
38 | step s{ | |
39 | sc ript{ | |
40 | def bldENV =ENV?.trim ().toUpper Case() | |
41 | echo "dete rmine regi on for ${b ldENV}" | |
42 | def region =bldENV[0. .2] | |
43 | echo "dete rmine main env for r egion ${re gion}, (ak a ${bldENV })" | |
44 | def mainEN V=bldENV[- 3..-1] | |
45 | echo "dete rmine acti on for ${b ldENV}, (a ka ${regio n}, ${main ENV})" | |
46 | switch(reg ion){ | |
47 | case "AW S": | |
48 | echo " AWS enviro nment, Pre pare Halfa ker worksp ace" | |
49 | dir("$ {TAS_GATEW AY}"){ | |
50 | get HalfakerCo de() | |
51 | } | |
52 | break | |
53 | case "MA G": | |
54 | echo ( "Initializ e workspac e from RTC ") | |
55 | if (!T GT_STREAM? .trim().to UpperCase( ).equals(" DEV")){ | |
56 | STAG ING_DIR="$ {WEB_BASED IR}/rtc/ta s" | |
57 | } | |
58 | teamco ncert([ | |
59 | buil dType: [ | |
60 | bu ildDefinit ion: "${bu ildDefinit ionId}", | |
61 | va lue: 'buil dDefinitio n' | |
62 | ] | |
63 | ]) | |
64 | echo ( "Verify co mponent ($ {TAS_GATEW AY}) exist s") | |
65 | sh ''' | |
66 | if [ [ -d "${TA S_GATEWAY} " ]] | |
67 | then | |
68 | ec ho "Compon ent (${TAS _GATEWAY}) exists, s afe to pro ceed" | |
69 | else | |
70 | fa il "FAIL: No compone nt (${TAS_ GATEWAY}) found" | |
71 | fi | |
72 | ''' | |
73 | echo " MAG enviro nment, det ermine SRC _STREAM" | |
74 | if(mai nENV.equal s("DEV") & & SRC_STR EAM?.trim( ).toUpperC ase().equa ls("HAF")) { | |
75 | echo "need to get HAF co de" | |
76 | dir( "${localTM P}"){ | |
77 | ge tHalfakerC ode() | |
78 | ec ho "need t o check la stGitCommi t against lastGitTag " | |
79 | } | |
80 | dir( "${TAS_GAT EWAY}"){ | |
81 | sh 'cp -p .p roject ../ tasGateway .project' | |
82 | sh 'rsync -a cvWh "${lo calTMP}/" . --exclud e ".git" - -del' | |
83 | sh 'mv ../ta sGateway.p roject .pr oject' | |
84 | } | |
85 | } | |
86 | break | |
87 | default: | |
88 | echo " local envi ronment, P repare Hal faker work space" | |
89 | dir("$ {TAS_GATEW AY}"){ | |
90 | getH alfakerCod e() | |
91 | } | |
92 | } | |
93 | } | |
94 | } | |
95 | } | |
96 | stage( 'Pre-Build Setup'){ | |
97 | step s{ | |
98 | ec ho ("creat e artifact location for jenkin s (${ARTIF ACT_LOCATI ON})") | |
99 | sh 'mkdir -p ${ARTIFAC T_LOCATION }' | |
100 | ec ho "set fi nal packag eVersion" | |
101 | di r("${produ ctBuildDir }"){ | |
102 | script{ | |
103 | if(ENV?. trim().toU pperCase() .startsWit h("MAG")){ | |
104 | echo " building i n MAG, do not use gi t commit i n packageV ersion" | |
105 | packag eVersion=" ${packageV ersion}_${ dateString }" | |
106 | } | |
107 | else { | |
108 | echo " git build" | |
109 | lastCo mmitID=get LastGitCom mit() | |
110 | echo " last commi t is ${las tCommitID} " | |
111 | if(las tCommitID? .trim()){ | |
112 | pa ckageVersi on="${pack ageVersion }_${lastCo mmitID}" | |
113 | } | |
114 | } | |
115 | echo "fi nal packag eVersion f or tag ${p ackageVers ion}" | |
116 | DIST_OUT PUT_FILE=" ${packageV ersion}.ta r" | |
117 | DIST_OUT PUT_FILENA ME="${pack ageVersion }.tar.gz" | |
118 | echo "bu ilding for package $ {DIST_OUTP UT_FILENAM E}" | |
119 | } | |
120 | } | |
121 | } | |
122 | } | |
123 | stage( 'Build and Deploy') { | |
124 | step s{ | |
125 | di r ("${prod uctBuildDi r}"){ | |
126 | script{ | |
127 | DIST_O UTPUT_FILE ="${packag eVersion}. tar" | |
128 | DIST_O UTPUT_FILE NAME="${pa ckageVersi on}.tar.gz " | |
129 | sh """ | |
130 | echo "DIST_OUT PUT_FILE = ${DIST_OU TPUT_FILE} " | |
131 | echo "DIST_OUT PUT_FILENA ME = ${DIS T_OUTPUT_F ILENAME}" | |
132 | sudo docker bu ild . -f . /dockerfil es/${docke rfile} -t "${gateway TAG}" | |
133 | sudo docker im ages | |
134 | sudo docker sa ve ${gatew ayTAG} > $ {DIST_OUTP UT_FILE} | |
135 | sudo gzip ${DI ST_OUTPUT_ FILE} | |
136 | """ | |
137 | if (fi leExists(" ${DIST_OUT PUT_FILENA ME}")) { | |
138 | echo "${DIST_O UTPUT_FILE NAME} crea ted, ready to packag e" | |
139 | } | |
140 | else { | |
141 | erro r "FAIL: $ {DIST_OUTP UT_FILENAM E} not rea dy" | |
142 | } | |
143 | } | |
144 | } | |
145 | } | |
146 | } | |
147 | stage( 'Verify Do cker Image ') { | |
148 | step s{ | |
149 | ec ho "Verify package $ {DIST_OUTP UT_FILENAM E}" | |
150 | di r ("${prod uctBuildDi r}"){ | |
151 | //sh "sudo docker im port ${DIS T_OUTPUT_F ILENAME} $ {gatewayTA G}" | |
152 | echo "Veri fy TAS Gat eway Docke r Image Im ported Suc cessfully" | |
153 | getInspect ionStatus( ) | |
154 | } | |
155 | } | |
156 | } | |
157 | stage( 'Stage Pac kage') { | |
158 | step s{ | |
159 | ec ho "stage the packag ed distrib ution (${D IST_OUTPUT _FILENAME} ) for ${pa ckageVersi on}" | |
160 | di r ("${prod uctBuildDi r}"){ | |
161 | stageLates tArtifact( "${DIST_OU TPUT_FILEN AME}") | |
162 | } | |
163 | } | |
164 | } | |
165 | } | |
166 | post{ | |
167 | // add t he cleanup to remove the image s | |
168 | always { | |
169 | echo "POST alw ays: all t asks are c ompleted, collecting environme nt variabl es to ${WO RKSPACE}/$ {BUILD_TAG }.log" | |
170 | sh ' printenv > > $WORKSPA CE/$BUILD_ TAG.log' | |
171 | echo "POST alw ays: archi ving all l ogs and ar tifacts sp ecified" | |
172 | publ ishHTML ta rget: [all owMissing: true, alw aysLinkToL astBuild: false, kee pAll: true , reportDi r: 'covera ge', repor tFiles: 'i ndex.html' , reportNa me: 'CodeC overage', reportTitl es: ''] | |
173 | } | |
174 | succes s{ | |
175 | echo 'POST suc cess: chec k environm ent to det ermine com mit action s' | |
176 | scri pt { | |
177 | de f myENV="$ {ENV}" | |
178 | de f subENV=m yENV[0..2] | |
179 | de f MAG_ARTI FACT_LOCAT ION = "${W ORKSPACE}/ ${TAS_GATE WAY_BUILD_ ARTIFACTS} /${package Version}" | |
180 | ec ho "POST s uccess: de termine pr oper commi t action f or ${myENV }, (aka ${ subENV})" | |
181 | sw itch(subEN V.toUpperC ase()){ | |
182 | case "AWS" : | |
183 | echo "PO ST success : AWS envi ronment, u se git to tag this b uild" | |
184 | gitTagBu ild() | |
185 | echo "PO ST success : in AWS, make hipch at notific ation" | |
186 | //notify Hipchat(cu rrentBuild .result,hc Room) | |
187 | break | |
188 | case "MAG" : | |
189 | echo "PO ST success : copy pac kaged arti fact (${DI ST_OUTPUT_ FILE}) to ${TAS_GATE WAY_BUILD_ ARTIFACTS} " | |
190 | sh """ | |
191 | pwd | |
192 | ls - la | |
193 | mkdir -p "${MAG_ ARTIFACT_L OCATION}" | |
194 | mv "${ WORKSPACE} /${product BuildDir}/ ${DIST_OUT PUT_FILENA ME}" "${MA G_ARTIFACT _LOCATION} /" | |
195 | echo " POST succe ss: check ${MAG_ARTI FACT_LOCAT ION}/${DIS T_OUTPUT_F ILENAME}" | |
196 | if [[ -f "${MAG_ ARTIFACT_L OCATION}/$ {DIST_OUTP UT_FILENAM E}" ]] | |
197 | then | |
198 | echo "POST suc cess: Arti fact (${MA G_ARTIFACT _LOCATION} /${DIST_OU TPUT_FILEN AME}) exis ts, safe t o proceed" | |
199 | else | |
200 | fail "FAIL: PO ST success : No artif act (${MAG _ARTIFACT_ LOCATION}/ ${DIST_OUT PUT_FILENA ME}) found " | |
201 | fi | |
202 | """ | |
203 | echo "cl eanup prio r to check in and del iver" | |
204 | dir("${p roductBuil dDir}"){ | |
205 | sh 'fi nd . -name "*.@*" -t ype f -del ete' | |
206 | } | |
207 | rtcCheck in() | |
208 | rtcDeliv er() | |
209 | echo "PO ST success : send ema il notific ation" | |
210 | //notify BuildStatu s(currentB uild.resul t) | |
211 | break | |
212 | default: | |
213 | echo "POS T success: local env ironment, send no no tices" | |
214 | echo "POS T success: local env ironment, do not com mit any ta g" | |
215 | } | |
216 | } | |
217 | echo "POST suc cess: coll ecting con sole log" | |
218 | getC onsoleLog( ) | |
219 | arch iveArtifac ts allowEm ptyArchive : true, ar tifacts: ' **/*.log, *.html, *. tar.gz' , onlyIfSucc essful: fa lse | |
220 | echo 'POST suc cess: Perf orming cle anup tasks after bui ld success ' | |
221 | dele teDir() | |
222 | } | |
223 | failur e{ | |
224 | scri pt{ | |
225 | if (BUILD_URL .toLowerCa se().conta ins("aws") ){ | |
226 | echo "POST failure: in AWS, ma ke hipchat notificat ion" | |
227 | //notifyHi pchat(curr entBuild.r esult,hcRo om) | |
228 | } | |
229 | if (ENV.toLow erCase().c ontains("l ocal")){ | |
230 | echo "PO ST failure : local en vironment, send no n otices" | |
231 | } | |
232 | el se{ | |
233 | echo "POST failure: send email notificat ion" | |
234 | //notifyBu ildStatus( currentBui ld.result) | |
235 | } | |
236 | } | |
237 | echo "POST fai lure: coll ecting con sole log" | |
238 | getC onsoleLog( ) | |
239 | arch iveArtifac ts allowEm ptyArchive : true, ar tifacts: ' **/*.log, *.tar.gz, *.tar' , o nlyIfSucce ssful: fal se | |
240 | echo 'POST fai lure: Perf orming cle anup tasks for build failure' | |
241 | dele teDir() | |
242 | } | |
243 | } | |
244 | } | |
245 | ||
246 | ||
247 | // load wo rkspace | |
248 | def getBra nchName(){ | |
249 | def bran ch="${GIT_ BRANCH}" | |
250 | return b ranch.toke nize('/')[ 1].toLower Case() | |
251 | } | |
252 | ||
253 | def getHal fakerCode( ){ | |
254 | branch_n ame=getBra nchName() | |
255 | echo "($ {branch_na me}), [${G IT_BRANCH} ]" | |
256 | echo "ge t the code " | |
257 | sh """ | |
258 | git co nfig --glo bal core.a utocrlf fa lse | |
259 | git co nfig --glo bal creden tial.helpe r 'cache - -timeout=3 600' | |
260 | """ | |
261 | git cred entialsId: 'jenkins_ build', ur l: "${mccf _git_repo} ", poll: f alse, bran ch: "${bra nch_name}" | |
262 | echo ("g et last gi t tag") | |
263 | lastGitT ag=gitDesc ribe() | |
264 | def last Commit=get LastGitCom mit() | |
265 | echo ("c heck lastG itTag (${l astGitTag} )") | |
266 | echo ("n eed to ver ify last c ommit (${l astCommit} ) is part of last ta g (${lastG itTag}), s o we can c heckin") | |
267 | if ( las tGitTag?.t rim() ){ | |
268 | echo ( "Ready to build ${la stGitTag} (${lastCom mit})") | |
269 | } | |
270 | else { | |
271 | error( "FAIL: no source pul led from $ {mccf_git_ repo}") | |
272 | } | |
273 | } | |
274 | ||
275 | // git fu nctions | |
276 | def getCha ngesets(){ | |
277 | def ch angeLogSet s = curren tBuild.cha ngeSets | |
278 | echo " reviewing changesets :" | |
279 | def co mmitMessag e="" | |
280 | for (i nt i = 0; i < change LogSets.si ze(); i++) { | |
281 | de f entries = changeLo gSets[i].i tems | |
282 | fo r (int j = 0; j < en tries.leng th; j++) { | |
283 | def entr y = entrie s[j] | |
284 | commitMe ssage="${c ommitMessa ge} \n ${e ntry.commi tId} by ${ entry.auth or} on ${n ew Date(en try.timest amp)}" | |
285 | echo "${ entry.comm itId} by $ {entry.aut hor} on ${ new Date(e ntry.times tamp)}: ${ entry.msg} " | |
286 | def file s = new Ar rayList(en try.affect edFiles) | |
287 | for (int k = 0; k < files.si ze(); k++) { | |
288 | def file = fil es[k] | |
289 | echo " ${file .editType. name} ${fi le.path}" | |
290 | } | |
291 | } | |
292 | } | |
293 | return "${commit Message}" | |
294 | } | |
295 | ||
296 | def gitDe scribe(){ | |
297 | echo "ge tting last git tag" | |
298 | def MYIN FO | |
299 | def tagE xists=sh(r eturnStdou t: true, s cript: 'gi t tag --li st').trim( ) | |
300 | if ( tag Exists?.tr im() ) { | |
301 | MYINFO =sh(return Stdout: tr ue, script : 'git des cribe').tr im() | |
302 | } | |
303 | else { | |
304 | MYINFO =sh(return Stdout: tr ue, script : 'git des cribe --al ways').tri m() | |
305 | } | |
306 | echo ("w e need to parse ${MY INFO} to d etermine i f the late st tag is the latest commit") | |
307 | MYINFO | |
308 | } | |
309 | def getLas tGitCommit (){ | |
310 | echo "ge tting last git commi t" | |
311 | def LAST _COMMIT | |
312 | LAST_COM MIT = sh ( | |
313 | script : 'git rev -parse HEA D', | |
314 | return Stdout: tr ue | |
315 | ).trim() | |
316 | echo ("t he last co mmit is ${ LAST_COMMI T[0..6]}") | |
317 | LAST_COM MIT[0..6] | |
318 | } | |
319 | ||
320 | def gitTag Build(){ | |
321 | withCred entials([u sernamePas sword(cred entialsId: 'jenkins_ build', pa sswordVari able: 'jen kinsPass', usernameV ariable: ' jenkinsUse r')]) { | |
322 | def MY HOSTNAME=g etHostname () | |
323 | def co mmit_messa ge = /"jen kins-${JOB _BASE_NAME }-${BUILD_ NUMBER}-${ MYHOSTNAME }"/ | |
324 | sh 'gi t config - -list' | |
325 | echo " set the us er.name, u ser.email" | |
326 | def uE mail = /"m ccfsystema dmins@half aker.com"/ | |
327 | sh """ | |
328 | git config use r.name "${ jenkinsUse r}" | |
329 | git config use r.email ${ uEmail} | |
330 | git config --g lobal push .default s imple | |
331 | git config ali as.version log "notes --ref=ver sionlog ap pend" | |
332 | git config --a dd remote. origin.pus h '+refs/n otes/*:ref s/notes/*' | |
333 | git config --a dd remote. origin.fet ch '+refs/ notes/*:re fs/notes/* ' | |
334 | git remote set -url origi n ${GIT_UR L} | |
335 | git config --l ist | |
336 | """ | |
337 | echo " append ver sion note to this co mmit" | |
338 | addGit VersionLog () | |
339 | echo " tag this c ommit" | |
340 | sh """ | |
341 | git tag -a ${p ackageVers ion} -m '$ {commit_me ssage}' ${ lastCommit ID} | |
342 | echo "push cha nges to re mote" | |
343 | git push origi n --tags - -verbose | |
344 | """ | |
345 | } | |
346 | } | |
347 | ||
348 | def addGit VersionLog (){ | |
349 | def last BuildDate= new Date(c urrentBuil d.startTim eInMillis) .format('M MM dd, yyy y HH:mm:ss Z') | |
350 | def vers ionString= "version: ${packageV ersion}" | |
351 | def buil dDateStrin g="lastBui ldDate: ${ lastBuildD ate}" | |
352 | def dist ributionSt ring="dist ributionFi leName: <s taging_url >/${DIST_O UTPUT_FILE NAME}" | |
353 | sh """ | |
354 | git ve rsionlog $ {lastCommi tID} -m "$ {versionSt ring}, ${b uildDateSt ring}, ${d istributio nString}" | |
355 | """ | |
356 | } | |
357 | ||
358 | // helper functions | |
359 | def getHos tname(){ | |
360 | def THIS HOSTNAME | |
361 | if(isUni x()){ | |
362 | THISHO STNAME = s h ( | |
363 | scri pt: 'hostn ame', | |
364 | retu rnStdout: true | |
365 | ).trim () | |
366 | } | |
367 | else { | |
368 | THISHO STNAME = b at ( | |
369 | scri pt: 'hostn ame', | |
370 | retu rnStdout: true | |
371 | ).trim () | |
372 | } | |
373 | THISHOST NAME | |
374 | } | |
375 | ||
376 | def getPac kageName() { | |
377 | echo "ge tting pack age name" | |
378 | def MYNA ME | |
379 | MYNAME = sh ( | |
380 | scri pt: 'npm r un env | g rep npm_pa ckage_name | cut -d \"=\" -f 2 ', | |
381 | retu rnStdout: true | |
382 | ).trim () | |
383 | MYNAME | |
384 | } | |
385 | ||
386 | // RTC st eps for ch eckin and deliver | |
387 | def rtcChe ckin(){ | |
388 | withCred entials([u sernamePas sword(cred entialsId: 'RTC_BUIL D', userna meVariable : 'rtcUser ', passwor dVariable: 'rtcPass' )]) { | |
389 | // avai lable as a n env vari able, but will be ma sked if yo u try to p rint it ou t any whic h way | |
390 | def MY HOSTNAME=g etHostname () | |
391 | def la stBuildDat e=new Date (currentBu ild.startT imeInMilli s).format( 'MMM dd, y yyy HH:mm: ss Z') | |
392 | def ve rsionStrin g="version : ${packag eVersion}" | |
393 | def bu ildDateStr ing="lastB uildDate: ${lastBuil dDate}" | |
394 | def di stribution String="di stribution FileName: <staging_u rl>/${DIST _OUTPUT_FI LENAME}" | |
395 | def co mmitCommen t = /"${ve rsionStrin g}, ${buil dDateStrin g}, ${dist ributionSt ring},jenk ins-${JOB_ BASE_NAME} -${BUILD_N UMBER}-${M YHOSTNAME} "/ | |
396 | def wo rkitem = " ${RTC_WORK ITEM}" | |
397 | def co mponents= ["${TAS_GA TEWAY}"] | |
398 | ||
399 | echo " show scm s tatus" | |
400 | sh """ | |
401 | ${sc mtool} sho w status - u ${rtcUse r} -P ${rt cPass} -v --all -d $ {TASWorksp ace} | |
402 | echo "----- -- --- ----- ----- ---- -" | |
403 | """ | |
404 | ||
405 | echo " prepare to checkin c omponents" | |
406 | for (c omponent i n componen ts){ | |
407 | echo "loop thr ough each file in $c omponent" | |
408 | sh " "" | |
409 | fi nd $compon ent -maxde pth 1 -typ e f -name '.*' -exec ${scmtool } checkin -u ${rtcUs er} -P ${r tcPass} -- comment ${ commitComm ent} --wor kitem ${wo rkitem} -v -d ${TASW orkspace} ${TASWorks pace}/{} \ \; | |
410 | """ | |
411 | echo "${scmtoo l} checkin $componen t/*" | |
412 | sh " ${scmtool} checkin - u ${rtcUse r} -P ${rt cPass} --c omment ${c ommitComme nt} --work item ${wor kitem} -v -d ${TASWo rkspace} $ {TASWorksp ace}/$comp onent/*" | |
413 | echo "----- -- --- ----- ----- ---- -" | |
414 | } | |
415 | // th e followin g is not v alid until rtc 6.0.4 | |
416 | // ste p([$class: 'RTCPostB uildDelive rPublisher ', failOnE rror: true ]) | |
417 | } | |
418 | } | |
419 | ||
420 | def rtcDel iver(){ | |
421 | withCred entials([u sernamePas sword(cred entialsId: 'RTC_BUIL D', userna meVariable : 'rtcUser ', passwor dVariable: 'rtcPass' )]) { | |
422 | // avail able as an env varia ble, but w ill be mas ked if you try to pr int it out any which way | |
423 | def wo rkitem = " ${RTC_WORK ITEM}" | |
424 | echo " show scm s tatus" | |
425 | sh """ | |
426 | ${sc mtool} sho w status - u ${rtcUse r} -P ${rt cPass} -v --all -d $ {TASWorksp ace} | |
427 | echo "----- -- --- ----- ----- ---- -" | |
428 | """ | |
429 | echo " RTC ${rtcU ser} deliv er " | |
430 | def de liverStatu s=sh ( | |
431 | script : "${scmto ol} delive r -u ${rtc User} -P $ {rtcPass} -v", | |
432 | return Status: tr ue | |
433 | ) | |
434 | if (de liverStatu s == 0 || deliverSta tus == 52 || deliver Status == 53){ | |
435 | echo "Deliver succeeded" | |
436 | retu rn 0 | |
437 | } | |
438 | el se if (del iverStatus == 11) { | |
439 | echo "Acce pt incomin g changes" | |
440 | def accept Status=sh ( | |
441 | script: "$ {scmtool} accept -u ${rtcUser} -P ${rtcP ass} -v", | |
442 | returnStat us: true | |
443 | ) | |
444 | if (accept Status == 0) { | |
445 | def redo DeliverSta tus=sh ( | |
446 | scri pt: "${scm tool} deli ver -u ${r tcUser} -P ${rtcPass } -v", | |
447 | retu rnStatus: true | |
448 | ) | |
449 | if ( redodelive rStatus == 0 || deli verStatus == 52 || d eliverStat us == 53){ | |
450 | ec ho "Accept and Deliv er succeed ed" | |
451 | re turn 0 | |
452 | } | |
453 | } | |
454 | } | |
455 | else { | |
456 | currentBui ld.result= 'FAILED' | |
457 | erro r("FAIL: S CM deliver failed wi th ${deliv erStatus}" ) | |
458 | } | |
459 | // the following is not va lid until rtc 6.0.4 | |
460 | //step ([$class: 'RTCPostBu ildDeliver Publisher' , failOnEr ror: true] ) | |
461 | } | |
462 | } | |
463 | ||
464 | def rtcBas eline(){ | |
465 | withCred entials([u sernamePas sword(cred entialsId: 'RTC_BUIL D', userna meVariable : 'rtcUser ', passwor dVariable: 'rtcPass' )]) { | |
466 | // avai lable as a n env vari able, but will be ma sked if yo u try to p rint it ou t any whic h way | |
467 | echo " RTC list w orkspaces " | |
468 | def wo rkspaceLis t=sh ( | |
469 | script : "${scmto ol} list w orkspaces -r local - v", | |
470 | return Stdout: tr ue | |
471 | ).trim () | |
472 | ||
473 | echo " workspace: ${workspa ceList}" | |
474 | ||
475 | echo " RTC ${rtcU ser} creat e baseline " | |
476 | sh """ | |
477 | ${sc mtool} cre ate baseli ne -u ${rt cUser} -P ${rtcPass} --all ${w orkspaceLi st} ${pack ageVersion } | |
478 | """ | |
479 | // th e followin g is not v alid until rtc 6.0.4 | |
480 | // ste p([$class: 'RTCPostB uildDelive rPublisher ', failOnE rror: true ]) | |
481 | } | |
482 | } | |
483 | ||
484 | ||
485 | // get do cker image inspect s tatus | |
486 | def getIns pectionSta tus(){ | |
487 | def insp ectionStat us=sh ( | |
488 | script: "sudo dock er image i nspect ${g atewayTAG} ", | |
489 | returnSt atus: true | |
490 | ) | |
491 | if (insp ectionStat us == 0){ | |
492 | echo " TAS Gatewa y Docker I mage Impor ted Succes sfully" | |
493 | return 0 | |
494 | } | |
495 | else { | |
496 | error "FAIL: TAS Gateway D ocker Imag e did not import" | |
497 | } | |
498 | } | |
499 | ||
500 | def stageL atestArtif act(artifa ct){ | |
501 | echo " stage the latest bui ld artifac t(${artifa ct}) for d eployment" | |
502 | def ar tifact_nam e= artifac t.tokenize ('/').last () | |
503 | def st aging = ST AGING_DIR. trim().toL owerCase() | |
504 | def la test = "${ WEB_BASEDI R}/latest_ tasgateway _dev" | |
505 | echo " check for TGT_STREAM " | |
506 | if(env .TGT_STREA M && env.T GT_STREAM? .trim()){ | |
507 | ec ho "TGT_ST REAM found (${TGT_ST REAM})" | |
508 | de f link=TGT _STREAM.tr im().toLow erCase() | |
509 | la test = "${ WEB_BASEDI R}/latest_ tasgateway _${link}" | |
510 | } | |
511 | try { | |
512 | ec ho "check ${staging} directory exist" | |
513 | sh "[[ -d ${ staging} ] ] || sudo mkdir -p $ {staging}" | |
514 | ec ho "fix di rectory pe rmissions" | |
515 | sh """ | |
516 | set -x | |
517 | sudo find \$(dirname ${STAGING _DIR}) -ty pe d -exec chmod 075 5 {} \\; | |
518 | "" " | |
519 | ec ho "copy $ {artifact} to ${stag ing}/" | |
520 | sh "sudo cp ${artifact } ${stagin g}/" | |
521 | ec ho "create symbolic link to st aged artif act" | |
522 | sh "sudo ln -sfn ${sta ging}/${ar tifact_nam e} ${lates t}" | |
523 | ec ho "verify link crea ted" | |
524 | de f linkExis ts=sh ( | |
525 | script: "readlink ${latest}" , | |
526 | returnSt dout: true | |
527 | ).trim() | |
528 | sh """ | |
529 | if [[ -n "${linkEx ists}" ]]; then | |
530 | echo "link exi sts for ${ latest}" | |
531 | else | |
532 | echo "link not found ${l atest}" | |
533 | fi | |
534 | "" " | |
535 | } catc h(Exceptio n e){ | |
536 | ec ho "someth ing bad ha ppened whi le staging artifact, throw and fail" | |
537 | ec ho e.toStr ing() | |
538 | th row e | |
539 | } | |
540 | } | |
541 | ||
542 | // notify Hipchat | |
543 | // will s end color coded noti fications to hipchat | |
544 | // | |
545 | def notif yHipchat(S tring buil dStatus = 'STARTED', String hc Room = '32 42078') { | |
546 | // build status of null means successfu l | |
547 | buildSta tus = bui ldStatus ? : 'SUCCESS FUL' | |
548 | ||
549 | def last Build = cu rrentBuild .getPrevio usBuild() | |
550 | ||
551 | // Defa ult values | |
552 | def colo r = 'RED' | |
553 | def colo rCode = '# FF0000' | |
554 | def subj ect = "${b uildStatus }: Job '${ env.JOB_NA ME} [${env .BUILD_NUM BER}]'" | |
555 | def summ ary = "${s ubject} ($ {env.BUILD _URL})" | |
556 | ||
557 | // Ov erride def ault value s based on build sta tus | |
558 | if (buil dStatus == 'STARTED' ) { | |
559 | color = 'YELLOW' | |
560 | colorC ode = '#FF FF00' | |
561 | } | |
562 | else if (buildStat us == 'SUC CESSFUL') { | |
563 | color = 'GREEN' | |
564 | colorC ode = '#00 FF00' | |
565 | if( la stBuild && lastBuild .getResult ().toStrin g()=="FAIL URE" ){ | |
566 | buil dStatus = 'FIXED' | |
567 | } | |
568 | } | |
569 | else if (buildStat us == 'ABO RTED') { | |
570 | color = 'PURPLE' | |
571 | colorC ode = '#80 0080' | |
572 | } | |
573 | else if (buildStat us == 'UNS TABLE') { | |
574 | color = 'GRAY' | |
575 | colorC ode = '#80 8080' | |
576 | } | |
577 | else { | |
578 | color = 'RED' | |
579 | colorC ode = '#FF 0000' | |
580 | } | |
581 | ||
582 | // Sen d notifica tions | |
583 | echo "se nd notice of ${build Status} to hipchat r oom: ${hcR oom}" | |
584 | def hcMe ssage=getC hangesets( ) | |
585 | if(build Status == 'SUCCESSFU L'){ | |
586 | echo " only send notice if previous b uild faile d" | |
587 | if( la stBuild && lastBuild .getResult ().toStrin g()=="FAIL URE" ){ | |
588 | echo "the prev ious build ${lastBui ld.getId() } failed, send updat e" | |
589 | hipc hatSend ( | |
590 | co lor: color , | |
591 | cr edentialId : 'jenkins _hc_notifi cation', | |
592 | me ssage: sum mary + ": changesets : " + hcM essage, | |
593 | no tify: true , | |
594 | ro om: hcRoom , | |
595 | se ndAs: 'jen kins_build ', | |
596 | te xtFormat: false, | |
597 | v2 enabled: t rue | |
598 | ) | |
599 | } | |
600 | else { | |
601 | echo "the prev ious build " + lastB uild.getRe sult().toS tring() | |
602 | } | |
603 | } | |
604 | else { | |
605 | echo " this build ${buildSt atus}" | |
606 | hipcha tSend ( | |
607 | colo r: color, | |
608 | cred entialId: 'jenkins_h c_notifica tion', | |
609 | mess age: summa ry + ": ch angesets: " + hcMes sage, | |
610 | noti fy: true, | |
611 | room : hcRoom, | |
612 | send As: 'jenki ns_build', | |
613 | text Format: fa lse, | |
614 | v2en abled: tru e | |
615 | ) | |
616 | } | |
617 | } | |
618 | ||
619 | def notif yBuildStat us(String buildStatu s = 'START ED') { | |
620 | // buil d status o f null mea ns success ful | |
621 | buildSta tus = bui ldStatus ? : 'SUCCESS FUL' | |
622 | ||
623 | // recipie ntProvider s (optiona l) | |
624 | // $class: CulpritsR ecipientPr ovider | |
625 | // Sends e mail to th e list of users who committed a change s ince the l ast non-br oken build till now. | |
626 | // This li st at leas t always i nclude peo ple who ma de changes in this b uild, but if the pre vious buil d | |
627 | // was a f ailure it also inclu des the cu lprit list from ther e. | |
628 | ||
629 | // $class: Developer sRecipient Provider | |
630 | // Sends e mail to al l the peop le who cau sed a chan ge in the change set . | |
631 | ||
632 | // $class: FailingTe stSuspects RecipientP rovider | |
633 | // Sends e mail to th e list of users susp ected of c ausing a u nit test t o begin fa iling. | |
634 | // This li st include s committe rs and req uestors of the build where the test bega n to fail, | |
635 | // and tho se for any consecuti ve failed builds pri or to the build in w hich the t est began to fail. | |
636 | ||
637 | // $class: FirstFail ingBuildSu spectsReci pientProvi der | |
638 | // Sends e mail to th e list of users susp ected of c ausing the build to begin fail ing. | |
639 | ||
640 | // $class: ListRecip ientProvid er | |
641 | // Sends e mail to th e list of recipients defined i n the "Pro ject Recip ient List. " | |
642 | ||
643 | // $class: Requester RecipientP rovider | |
644 | // Sends e mail to th e user who initiated the build . | |
645 | ||
646 | // $class: UpstreamC omitterRec ipientProv ider | |
647 | // Sends e mail to th e list of users who committed changes in upstream builds tha t triggere d this bui ld | |
648 | // Defaul t values L istRecipie ntProvider | |
649 | def reci pients=[[$ class: 'Li stRecipien tProvider' ]] | |
650 | def subj ect = "${b uildStatus }: Job '${ env.JOB_NA ME} [${env .BUILD_NUM BER}]'" | |
651 | def repl yto = "${e nv.DEFAULT _REPLYTO}" | |
652 | def mime Type = "te xt/html" | |
653 | def send to = "${en v.DEFAULT_ RECIPIENTS }" | |
654 | def deta ils = """ | |
655 | <p>Job : '${env.J OB_NAME} b uild: [${e nv.BUILD_N UMBER}]':< /p> | |
656 | <p>Che ck console output at "<a href= "${env.BUI LD_URL}">$ {env.JOB_N AME} [${en v.BUILD_NU MBER}]</a> "</p> | |
657 | """ | |
658 | ||
659 | // Ov erride def ault value s based on build sta tus | |
660 | if (buil dStatus == 'STARTED' || buildS tatus == ' SUCCESSFUL ' || build Status == 'FIXED') { | |
661 | recipi ents = [[$ class: 'De velopersRe cipientPro vider']] | |
662 | } | |
663 | ||
664 | else if (buildStat us == 'ABO RTED' || b uildStatus == 'UNSTA BLE') { | |
665 | recipi ents = [[$ class: 'De velopersRe cipientPro vider']] | |
666 | } | |
667 | else { | |
668 | echo " unknown st atus" | |
669 | recipi ents = [[$ class: 'Cu lpritsReci pientProvi der'], [$c lass: 'Req uesterReci pientProvi der']] | |
670 | } | |
671 | // example s | |
672 | // Notify Culprits a nd Request er via def ault EMail plugin | |
673 | // step([$ class: 'Ma iler', not ifyEveryUn stableBuil d: true, r ecipients: emailextr ecipients( [[$class: 'CulpritsR ecipientPr ovider'], [$class: ' RequesterR ecipientPr ovider']]) ]) | |
674 | ||
675 | // Send an email to abc plus a ny address es returne d by the p roviders | |
676 | // emailex t body: 'A Test EMai l', | |
677 | // recipien tProviders : [[$class : 'Develop ersRecipie ntProvider '], [$clas s: 'Reques terRecipie ntProvider ']], | |
678 | // subject: 'Test', | |
679 | // to: 'abc ' | |
680 | echo "se nd email t o recipien ts (${reci pients}) f or ${build Status}" | |
681 | echo """ | |
682 | subj ect: ${sub ject}, | |
683 | body : ${detail s}, | |
684 | reci pientProvi ders: ${re cipients}, | |
685 | repl yTo: ${rep lyto}, | |
686 | to: ${sendto} | |
687 | """ | |
688 | mail ( | |
689 | body : details, | |
690 | cc: 'PII', | |
691 | mime Type: 'tex t/html', | |
692 | repl yTo: reply to, | |
693 | subj ect: subje ct, | |
694 | to: sendto | |
695 | ) | |
696 | } | |
697 | ||
698 | // save lo g to works pace | |
699 | def getCon soleLog(){ | |
700 | echo "ge tConsoleLo g: prepare logfilena me to get console lo g" | |
701 | def logF ilename="$ {JOB_URL}" | |
702 | def work spaceLog=" ${WORKSPAC E}/${JOB_B ASE_NAME}_ ${BUILD_NU MBER}_cons ole.log" | |
703 | echo "ge tConsoleLo g: console log is ${ logFilenam e} (same a s job url) " | |
704 | logFilen ame=logFil ename.trim ().replace ("${JENKIN S_URL}","$ {JENKINS_H OME}/") | |
705 | echo "ge tConsoleLo g: console log is ch anged to $ {logFilena me}" | |
706 | logFilen ame=logFil ename.trim ().replace All("job", "jobs") | |
707 | echo "ge tConsoleLo g: console log is ch anged agai n to ${log Filename}" | |
708 | logFilen ame="${log Filename}b uilds/${BU ILD_NUMBER }/log" | |
709 | echo "ge tConsoleLo g: console log is fi nally ${l ogFilename }" | |
710 | echo "ge tConsoleLo g: prepare to write to ${works paceLog}" | |
711 | sh """ | |
712 | sed -e "s,\\x1b\ \[[0-9]*.* \\x1b\\[0m ,,g;s,\\ba ctive\\b,a ctive\\\r, gm;s,\\x08 ,.,gm" "${ logFilenam e}" > "tmp .log" | |
713 | sed -e "s,\\x1b\ \[3[0-9][m GKA],,gm;s ,\\x1b\\[1 A,,gm;s,\\ x1b\\[2K,, gm;" "tmp. log" > "${ workspaceL og}" | |
714 | rm "tm p.log" | |
715 | echo " getConsole Log: verif y ${worksp aceLog} re ady for ar chival" | |
716 | if [[ -f "${work spaceLog}" ]] | |
717 | then | |
718 | echo "getConso leLog: loc al console log (${wo rkspaceLog }) exists, safe to p roceed" | |
719 | else | |
720 | echo "getConso leLog: No local cons ole log ($ {workspace Log}) foun d" | |
721 | fi | |
722 | """ | |
723 | } | |
724 | // Requir ed due to JENKINS-27 421 | |
725 | @NonCPS | |
726 | List<List< ?>> mapToL ist(Map ma p) { | |
727 | return m ap.collect { it -> | |
728 | [it.ke y, it.valu e] | |
729 | } | |
730 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.