diff --git a/Jenkinsfile b/Jenkinsfile index de0ebae..f8052d6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -82,19 +82,22 @@ pipeline { echo "✅ Terraform backend created successfully" } else { echo "⚠️ Terraform apply failed, checking if resources already exist..." - def bucketCheck = sh( - script: "aws s3api head-bucket --bucket ${TF_BACKEND_BUCKET} --region ${TF_VAR_aws_region} 2>/dev/null && echo 'exists' || echo 'missing'", - returnStdout: true - ).trim() - def tableCheck = sh( - script: "aws dynamodb describe-table --table-name ${TF_DDB_TABLE} --region ${TF_VAR_aws_region} 2>/dev/null && echo 'exists' || echo 'missing'", - returnStdout: true - ).trim() + def bucketExists = sh( + script: "aws s3api head-bucket --bucket ${TF_BACKEND_BUCKET} --region ${TF_VAR_aws_region} 2>/dev/null", + returnStatus: true + ) == 0 + def tableExists = sh( + script: "aws dynamodb describe-table --table-name ${TF_DDB_TABLE} --region ${TF_VAR_aws_region} 2>/dev/null", + returnStatus: true + ) == 0 - if (bucketCheck == "exists" && tableCheck == "exists") { + if (bucketExists && tableExists) { echo "✅ Terraform backend already exists - continuing..." } else { - error("❌ Backend bootstrap failed and resources don't exist. Manual intervention required.") + echo "❌ Backend bootstrap failed and resources don't exist:" + echo " S3 Bucket exists: ${bucketExists}" + echo " DynamoDB Table exists: ${tableExists}" + error("Manual intervention required.") } } }