@@ -304,77 +304,82 @@ pipeline {
304304 expression { return ! params. regressions }
305305 }
306306 }
307- agent {label ' javaClientLinuxPool' }
307+ agent {label ' javaClientLinuxPool' }
308308
309- steps{
310- script {
311-
309+ steps{
310+ script {
311+ withCredentials([
312+ string(credentialsId : ' aws-region-us-west' , variable : ' AWS_REGION' ),
313+ string(credentialsId : ' aws-role-headless-testing' , variable : ' AWS_ROLE' ),
314+ string(credentialsId : ' aws-role-account-headless' , variable : ' AWS_ROLE_ACCOUNT' )
315+ ]) {
316+ def deploymentResult = deployAWSInstance([
317+ instanceName : " java-client-instance-${ BUILD_NUMBER} " ,
318+ region : env. AWS_REGION ,
319+ credentialsId : ' headlessDbUserEC2' ,
320+ role : env. AWS_ROLE ,
321+ roleAccount : env. AWS_ROLE_ACCOUNT ,
322+ branch : ' master'
323+ ])
324+
325+ echo " ✅ Instance deployed: ${ deploymentResult.privateIp} "
326+ echo " ✅ Terraform directory: ${ deploymentResult.terraformDir} "
327+ echo " ✅ Workspace: ${ deploymentResult.workspace} "
328+ echo " ✅ Status: ${ deploymentResult.status} "
329+
330+ // Store deployment info for cleanup
331+ env. DEPLOYMENT_INSTANCE_NAME = deploymentResult. instanceName
332+ env. DEPLOYMENT_REGION = deploymentResult. region
333+ env. DEPLOYMENT_TERRAFORM_DIR = deploymentResult. terraformDir
334+ env. EC2_PRIVATE_IP = deploymentResult. privateIp
335+
336+ def nodeName = " java-client-agent-${ BUILD_NUMBER} "
337+ def remoteFS = " /space/jenkins_home"
338+ def labels = " java-client-agent-${ BUILD_NUMBER} "
339+ def instanceIp = env. EC2_PRIVATE_IP
340+
341+ // Attach volumes
342+ def volumeResult = attachInstanceVolumes([
343+ instanceIp : instanceIp,
344+ remoteFS : remoteFS,
345+ branch : ' master'
346+ ])
347+
348+ echo " ✅ Volume attachment completed: ${ volumeResult.volumeAttached} "
349+ echo " ✅ Java installed: ${ volumeResult.javaInstalled} "
350+
351+ // Install dependencies AND run init scripts
352+ def depsResult = installDependenciesAndInitScripts([
353+ instanceIp : instanceIp,
354+ packageFile : ' Packagedependencies' ,
355+ packageDir : ' terraform-templates/java-client-api' ,
356+ initScriptsDir : ' terraform-templates/java-client-api/scripts' ,
357+ initScriptsFile : ' terraform-templates/java-client-api/initscripts'
358+ ])
359+
360+ echo " ✅ Dependencies installed: ${ depsResult.dependenciesInstalled} "
361+ if (depsResult. initScriptsExecuted) {
362+ echo " ✅ Init scripts executed: ${ depsResult.initScriptsCount} scripts"
363+ } else {
364+ echo " ℹ️ No init scripts configured or executed"
365+ }
312366
313- def deploymentResult = deployAWSInstance([
314- instanceName : " java-client-instance-${ BUILD_NUMBER} " ,
315- region : ' us-west-2' ,
316- credentialsId : ' headlessDbUserEC2' ,
317- role : ' role-headless-testing' ,
318- roleAccount : ' 343869654284' ,
319- branch : ' master'
320- ])
321-
322- echo " ✅ Instance deployed: ${ deploymentResult.privateIp} "
323- echo " ✅ Terraform directory: ${ deploymentResult.terraformDir} "
324- echo " ✅ Workspace: ${ deploymentResult.workspace} "
325- echo " ✅ Status: ${ deploymentResult.status} "
326-
327- // Store deployment info for cleanup
328- env. DEPLOYMENT_INSTANCE_NAME = deploymentResult. instanceName
329- env. DEPLOYMENT_REGION = deploymentResult. region
330- env. DEPLOYMENT_TERRAFORM_DIR = deploymentResult. terraformDir
331- env. EC2_PRIVATE_IP = deploymentResult. privateIp
332-
333- def nodeName = " java-client-agent-${ BUILD_NUMBER} "
334- def remoteFS = " /space/jenkins_home"
335- def labels = " java-client-agent-${ BUILD_NUMBER} "
336- def instanceIp = env. EC2_PRIVATE_IP
337-
338- // Attach volumes
339- def volumeResult = attachInstanceVolumes([
340- instanceIp : instanceIp,
341- remoteFS : remoteFS,
342- branch : ' master'
343- ])
344-
345- echo " ✅ Volume attachment completed: ${ volumeResult.volumeAttached} "
346- echo " ✅ Java installed: ${ volumeResult.javaInstalled} "
347- // Install dependencies AND run init scripts
348- def depsResult = installDependenciesAndInitScripts([
349- instanceIp : instanceIp,
350- packageFile : ' Packagedependencies' ,
351- packageDir : ' terraform-templates/java-client-api' ,
352- initScriptsDir : ' terraform-templates/java-client-api/scripts' ,
353- initScriptsFile : ' terraform-templates/java-client-api/initscripts'
354- ])
355-
356- echo " ✅ Dependencies installed: ${ depsResult.dependenciesInstalled} "
357- if (depsResult. initScriptsExecuted) {
358- echo " ✅ Init scripts executed: ${ depsResult.initScriptsCount} scripts"
359- } else {
360- echo " ℹ️ No init scripts configured or executed"
361- }
362-
363- // Use shared library to create Jenkins agent
364- def agentResult = createJenkinsAgent([
365- nodeName : nodeName,
366- instanceIp : instanceIp,
367- remoteFS : remoteFS,
368- labels : labels,
369- timeoutMinutes : 5 ,
370- credentialsId : ' qa-builder-aws'
371- ])
372-
373- echo " ✅ Jenkins agent created: ${ agentResult.nodeName} "
374- echo " ✅ Agent status: ${ agentResult.status} "
375- }
376- }
377- }
367+ // Use shared library to create Jenkins agent
368+ def agentResult = createJenkinsAgent([
369+ nodeName : nodeName,
370+ instanceIp : instanceIp,
371+ remoteFS : remoteFS,
372+ labels : labels,
373+ timeoutMinutes : 5 ,
374+ credentialsId : ' qa-builder-aws'
375+ ])
376+
377+ echo " ✅ Jenkins agent created: ${ agentResult.nodeName} "
378+ echo " ✅ Agent status: ${ agentResult.status} "
379+ }
380+ }
381+ }
382+ }
378383
379384 stage(' regressions-11 arm infrastructure' ) {
380385 agent { label " java-client-agent-${ BUILD_NUMBER} " }
@@ -409,51 +414,57 @@ pipeline {
409414 }
410415
411416 post{
412- always {
413- script {
414- echo " 🧹 Starting cleanup process..."
415-
416- try {
417- // Cleanup Terraform infrastructure
418- if (env. EC2_PRIVATE_IP ) {
419- echo " 🗑️ Cleaning up Terraform resources..."
420- node(' javaClientLinuxPool' ) {
421- try {
422- sleep 60
423- unstash " terraform-${ BUILD_NUMBER} "
424- withAWS(credentials : ' headlessDbUserEC2' , region : ' us-west-2' , role : ' role-headless-testing' , roleAccount : ' 343869654284' , duration : 3600 ) {
425- sh ''' #!/bin/bash
426- export PATH=/home/builder/terraform:$PATH
427- cd ${WORKSPACE}/${DEPLOYMENT_TERRAFORM_DIR}
428- terraform workspace select dev
429- terraform destroy -auto-approve
430- '''
431- }
432- echo " ✅ Terraform resources destroyed successfully."
433- } catch (Exception terraformException) {
434- echo " ⚠️ Warning: Terraform cleanup failed: ${ terraformException.message} "
435- }
436- }
437- } else {
438- echo " ℹ️ No EC2 instance IP found, skipping Terraform cleanup"
439- }
440-
441- // Cleanup Jenkins agent using shared library function
442- def nodeName = " java-client-agent-${ BUILD_NUMBER} "
443- echo " 🗑️ Cleaning up Jenkins agent: ${ nodeName} "
444- try {
445- def cleanupResult = cleanupJenkinsAgent(nodeName)
446- echo " ✅ Cleanup result: ${ cleanupResult.status} for node: ${ cleanupResult.nodeName} "
447- } catch (Exception jenkinsCleanupException) {
448- echo " ⚠️ Warning: Jenkins agent cleanup failed: ${ jenkinsCleanupException.message} "
449- }
450- echo " ✅ Pipeline cleanup completed successfully."
451-
452- } catch (Exception cleanupException) {
453- echo " ⚠️ Warning: Cleanup encountered an error: ${ cleanupException.message} "
454- echo " 📋 Continuing with pipeline completion despite cleanup issues..."
455- }
456- }
457- }
417+ always {
418+ script {
419+ echo " 🧹 Starting cleanup process..."
420+
421+ try {
422+ // Cleanup Terraform infrastructure
423+ if (env. EC2_PRIVATE_IP ) {
424+ echo " 🗑️ Cleaning up Terraform resources..."
425+ node(' javaClientLinuxPool' ) {
426+ try {
427+ sleep 60
428+ unstash " terraform-${ BUILD_NUMBER} "
429+ withCredentials([
430+ string(credentialsId : ' aws-region-us-west' , variable : ' AWS_REGION' ),
431+ string(credentialsId : ' aws-role-headless-testing' , variable : ' AWS_ROLE' ),
432+ string(credentialsId : ' aws-role-account-headless' , variable : ' AWS_ROLE_ACCOUNT' )
433+ ]) {
434+ withAWS(credentials : ' headlessDbUserEC2' , region : env. AWS_REGION , role : env. AWS_ROLE , roleAccount : env. AWS_ROLE_ACCOUNT , duration : 3600 ) {
435+ sh ''' #!/bin/bash
436+ export PATH=/home/builder/terraform:$PATH
437+ cd ${WORKSPACE}/${DEPLOYMENT_TERRAFORM_DIR}
438+ terraform workspace select dev
439+ terraform destroy -auto-approve
440+ '''
441+ }
442+ }
443+ echo " ✅ Terraform resources destroyed successfully."
444+ } catch (Exception terraformException) {
445+ echo " ⚠️ Warning: Terraform cleanup failed: ${ terraformException.message} "
446+ }
447+ }
448+ } else {
449+ echo " ℹ️ No EC2 instance IP found, skipping Terraform cleanup"
450+ }
451+
452+ // Cleanup Jenkins agent using shared library function
453+ def nodeName = " java-client-agent-${ BUILD_NUMBER} "
454+ echo " 🗑️ Cleaning up Jenkins agent: ${ nodeName} "
455+ try {
456+ def cleanupResult = cleanupJenkinsAgent(nodeName)
457+ echo " ✅ Cleanup result: ${ cleanupResult.status} for node: ${ cleanupResult.nodeName} "
458+ } catch (Exception jenkinsCleanupException) {
459+ echo " ⚠️ Warning: Jenkins agent cleanup failed: ${ jenkinsCleanupException.message} "
460+ }
461+ echo " ✅ Pipeline cleanup completed successfully."
462+
463+ } catch (Exception cleanupException) {
464+ echo " ⚠️ Warning: Cleanup encountered an error: ${ cleanupException.message} "
465+ echo " 📋 Continuing with pipeline completion despite cleanup issues..."
466+ }
467+ }
468+ }
458469 }
459470}
0 commit comments