From a82509eb38a00f5516361b82a0d34643c0796091 Mon Sep 17 00:00:00 2001 From: arko0220 Date: Wed, 6 May 2026 18:27:16 +0500 Subject: [PATCH] fix: remove export big variables --- .../README-email-notification-json.md | 17 +++++----- .../calculate-email-notification-variables.sh | 1 - .../generate-email-notification-json.sh | 4 +-- push-metrics.sh | 32 +++++++++---------- 4 files changed, 25 insertions(+), 29 deletions(-) diff --git a/email-notification/README-email-notification-json.md b/email-notification/README-email-notification-json.md index 59b5564..7875d7b 100644 --- a/email-notification/README-email-notification-json.md +++ b/email-notification/README-email-notification-json.md @@ -41,8 +41,9 @@ This set of scripts is designed to analyze test results from the `allure-results After executing `generate-email-notification-json.sh`, the following environment variables are available: -- `GENERATED_JSON` - Content of the generated JSON file -- `JSON_FILE` - Path to the JSON results file +- `JSON_FILE` - Path to the JSON results file (read content with `jq`/`cat`; not exported as env to avoid ARG_MAX limits) + +Full JSON content is **not** exported as an environment variable; use `$JSON_FILE`. ## Environment Variables @@ -62,7 +63,7 @@ The script uses the following environment variables for JSON generation: - `REPORT_VIEW_HOST_URL` - Host for viewing reports - `ALLURE_REPORT_URL` - Path to reports folder - `TIMESTAMP` - Timestamp -- `TEST_DETAILS_STRING` - String with details of all tests (converted to JSON array) +- `TEST_DETAILS_STRING` - String with details of all tests (used during generation only; not exported — large runs would exceed ARG_MAX) ## Generated JSON Structure @@ -117,9 +118,9 @@ json_content=$(generate_email_notification_json) # Use the result echo "$json_content" -# Or use exported variables +# Or use exported path and read file echo "JSON file: $JSON_FILE" -echo "Content: $GENERATED_JSON" +jq . "$JSON_FILE" # File will be saved to: ../email-notification-generated/email-notification-results-generated.json ``` @@ -134,10 +135,8 @@ The `generate_email_notification_json` function does not accept parameters. ### Return Values -The function returns: -- **Generated JSON content** (output to stdout) -- **Environment variable `GENERATED_JSON`** - JSON content -- **Environment variable `JSON_FILE`** - path to JSON file +The function writes JSON to disk and exports: +- **Environment variable `JSON_FILE`** - path to JSON file (consumers read file; JSON is not stored in env) ## Differences from Text Version diff --git a/email-notification/calculate-email-notification-variables.sh b/email-notification/calculate-email-notification-variables.sh index b98ddc5..df237c5 100644 --- a/email-notification/calculate-email-notification-variables.sh +++ b/email-notification/calculate-email-notification-variables.sh @@ -145,7 +145,6 @@ for test_detail in "${test_details[@]}"; do TEST_DETAILS_STRING="$test_detail" fi done -export TEST_DETAILS_STRING="$TEST_DETAILS_STRING" # Display summary echo "" diff --git a/email-notification/generate-email-notification-json.sh b/email-notification/generate-email-notification-json.sh index 5dee041..104a227 100644 --- a/email-notification/generate-email-notification-json.sh +++ b/email-notification/generate-email-notification-json.sh @@ -239,11 +239,9 @@ generate_email_notification_json() { log_success "JSON generated successfully: $output_file" - # Export the JSON content as environment variable for use in other scripts - export GENERATED_JSON="$json_content" export JSON_FILE="$output_file" - log_info "Environment variables exported: GENERATED_JSON, JSON_FILE" + log_info "Environment variables exported: JSON_FILE" # Return the JSON content # echo "$json_content" diff --git a/push-metrics.sh b/push-metrics.sh index 864c822..16106e0 100644 --- a/push-metrics.sh +++ b/push-metrics.sh @@ -3,7 +3,7 @@ # Push test result metrics to Prometheus Pushgateway / VictoriaMetrics # # Reads from: -# - $GENERATED_JSON (env var set by generate_email_notification_json) +# - $JSON_FILE (path set by generate_email_notification_json) # - /tmp/clone/allure-results/*-result.json (individual Allure result files) # # Feature toggle: @@ -167,8 +167,8 @@ push_metrics() { return 1 fi - if [[ -z "${GENERATED_JSON:-}" ]]; then - echo "❌ push_metrics: GENERATED_JSON is not set. Run generate_email_notification_json first." + if [[ -z "${JSON_FILE:-}" ]] || [[ ! -f "${JSON_FILE}" ]]; then + echo "❌ push_metrics: JSON_FILE is not set or missing. Run generate_email_notification_json first." return 1 fi @@ -176,17 +176,17 @@ push_metrics() { local env="${ENVIRONMENT_NAME:-unknown}" # ------------------------------------------------------------------------- - # Parse scope-level statistics from GENERATED_JSON + # Parse scope-level statistics from JSON_FILE # ------------------------------------------------------------------------- local pass_rate total passed failed skipped overall_status - pass_rate=$(echo "$GENERATED_JSON" | jq -r '.test_results.pass_rate // 0') - total=$(echo "$GENERATED_JSON" | jq -r '.test_results.total_count // 0') - passed=$(echo "$GENERATED_JSON" | jq -r '.test_results.passed_count // 0') - failed=$(echo "$GENERATED_JSON" | jq -r '.test_results.failed_count // 0') - skipped=$(echo "$GENERATED_JSON" | jq -r '.test_results.skipped_count // 0') - overall_status=$(echo "$GENERATED_JSON" | jq -r '.test_results.overall_status // "UNKNOWN"') - - echo "GENERATED_JSON content parsing results:" + pass_rate=$(jq -r '.test_results.pass_rate // 0' "$JSON_FILE") + total=$(jq -r '.test_results.total_count // 0' "$JSON_FILE") + passed=$(jq -r '.test_results.passed_count // 0' "$JSON_FILE") + failed=$(jq -r '.test_results.failed_count // 0' "$JSON_FILE") + skipped=$(jq -r '.test_results.skipped_count // 0' "$JSON_FILE") + overall_status=$(jq -r '.test_results.overall_status // "UNKNOWN"' "$JSON_FILE") + + echo "JSON content parsing results:" echo "pass_rate: $pass_rate" echo "total: $total" echo "passed: $passed" @@ -304,13 +304,13 @@ push_metrics() { payload+="atp_test_case_duration_seconds{test_name=\"${safe_name}\",environment=\"${env}\",suite=\"${safe_suite}\"} ${duration}\n" done else - echo "⚠️ push_metrics: allure-results not found or empty, falling back to GENERATED_JSON test_details" + echo "⚠️ push_metrics: allure-results not found or empty, falling back to JSON_FILE test_details" local count - count=$(echo "$GENERATED_JSON" | jq '.test_details | length') + count=$(jq '.test_details | length' "$JSON_FILE") for ((i=0; i