# Variable Overrides for E2E Tests

NOTE: This is available only for E2E test suites as of now. This will be available for individual test suite execution soon.

# Overview

Variable overrides allow you to dynamically change variable values during E2E test execution without modifying your test definitions. This is particularly useful for running custom setup scripts (e.g. auth token generation, data setup) elsewhere in the pipeline and then using the data generated from such scripts during test execution in KushoAI runner.

# Variable Override Methods

# Method 1: Comma-Separated Format

The simplest way to override multiple variables is using a comma-separated key:value format.

Syntax:

VARIABLES="key1:value1,key2:value2,key3:value3"

Example:

docker run --rm \
  -e VARIABLES="api_key:abc123,user_id:999,timeout:30" \
  -e E2E_TEST_SUITE_UUID="e5d1b703-a798-4bd9-becb-8977bc2a1ec3" \
  -e EXECUTION_PROFILE_UUID="profile-uuid" \
  -e API_KEY="your-api-key" \
  -e ENVIRONMENT_ID="2" \
  public.ecr.aws/y5g4u6y7/kusho-test-runner:latest

Use Cases:

  • Quick overrides for simple values
  • CI/CD pipelines with straightforward variable requirements
  • Testing with different configurations

Notes:

  • Spaces around colons and commas are automatically trimmed
  • Values can contain colons (e.g., URLs) - only the first : is used as the separator
  • For values containing commas, use JSON format instead

# Method 2: JSON Format

For complex values or when you need more structure, use JSON format.

Syntax:

VARIABLES='{"key1":"value1","key2":"value2","key3":"value3"}'

Example:

docker run --rm \
  -e VARIABLES='{"api_base_url":"https://staging.api.com","auth_token":"Bearer_xyz123","tags":"smoke,regression,api"}' \
  -e E2E_TEST_SUITE_UUID="e5d1b703-a798-4bd9-becb-8977bc2a1ec3" \
  -e EXECUTION_PROFILE_UUID="profile-uuid" \
  -e API_KEY="your-api-key" \
  -e ENVIRONMENT_ID="2" \
  public.ecr.aws/y5g4u6y7/kusho-test-runner:latest

Use Cases:

  • Values containing special characters (commas, colons)
  • Complex nested values
  • When you need precise control over value types

Notes:

  • Must be valid JSON
  • Use single quotes around the JSON to avoid shell interpretation
  • Supports nested objects and arrays (they'll be stringified when used)

# Method 3: Individual Environment Variables

Override specific variables using the VARIABLE_ prefix, similar to Docker's -e flag approach.

Syntax:

VARIABLE_variable_name="value"

Example:

docker run --rm \
  -e VARIABLE_api_key="abc123" \
  -e VARIABLE_user_id="999" \
  -e VARIABLE_base_url="https://staging.example.com" \
  -e E2E_TEST_SUITE_UUID="e5d1b703-a798-4bd9-becb-8977bc2a1ec3" \
  -e EXECUTION_PROFILE_UUID="profile-uuid" \
  -e API_KEY="your-api-key" \
  -e ENVIRONMENT_ID="2" \
  public.ecr.aws/y5g4u6y7/kusho-test-runner:latest

Use Cases:

  • Overriding specific sensitive values (secrets, API keys)
  • CI/CD systems that handle secrets per environment variable
  • When you want to override only a few specific variables
  • Maximum security isolation (each secret as separate variable)

Notes:

  • The VARIABLE_ prefix is stripped to get the actual variable name
  • Individual variables have higher priority than VARIABLES
  • Ideal for marking specific variables as secrets in CI/CD systems

# Priority Order

Variables are resolved in the following order (highest to lowest priority):

  1. CLI Variable Overrides (highest priority)
    • Individual VARIABLE_* environment variables
    • VARIABLES environment variable (JSON or comma-separated)
  2. Pre-run Script Updates - Variables modified by pre-run scripts
  3. Default Values - Variables defined in the execution data

This priority system ensures that CLI overrides always take precedence, making them ideal for CI/CD customization.

# Combining Methods

All three methods can be used together, with the following precedence:

Priority: Individual VARIABLE_* > VARIABLES (JSON/comma-separated) > Pre-run Scripts > Defaults

# Security Considerations

# Variable Masking in Logs

For security, CLI variable override values are masked in execution logs:

  • Short values (≤6 characters): Fully masked with ******
  • Long values (>6 characters): Show first 3 and last 3 characters

Example Output:

🔧 CLI Variable Overrides: 3 variable(s)
   • api_base_url = htt**********************com
   • auth_token = Bea*********123
   • user_id = 999

# Troubleshooting

# Common Issues

Issue: Variables not being overridden

Solution: Check the priority order. Individual VARIABLE_* env vars have the highest priority. Ensure you're using the correct variable names.


Issue: JSON parsing error

Solution: Validate your JSON syntax. Use single quotes around JSON to avoid shell interpretation:

-e VARIABLES='{"key":"value"}'  # ✅ Correct
-e VARIABLES={"key":"value"}    # ❌ Wrong

Issue: Comma-separated format not working

Solution: Ensure you're using colons (:) to separate keys from values:

-e VARIABLES="key:value,foo:bar"  # ✅ Correct
-e VARIABLES="key=value,foo=bar"  # ❌ Wrong

Issue: Variable with comma in value not working

Solution: Use JSON format for values containing commas:

-e VARIABLES='{"tags":"smoke,regression,api"}'

# Debug Tips

  1. Check Execution Logs: The test runner displays which variables were loaded and overridden
  2. Verify Variable Names: Ensure variable names match exactly (case-sensitive)
  3. Test Locally: Run the Docker command locally to verify before CI/CD integration

# Limitations

  1. Environment Variable Conflicts: You cannot specify the same VARIABLES env var multiple times:

    # ❌ Won't work - only last value is used
    -e VARIABLES="key1:val1" -e VARIABLES="key2:val2"
    
    # ✅ Use comma-separated or individual vars instead
    -e VARIABLES="key1:val1,key2:val2"
    -e VARIABLE_key1="val1" -e VARIABLE_key2="val2"
  2. Comma-Separated Limitations: Values containing commas require JSON format
  3. Variable Name Restrictions: Follow standard environment variable naming (alphanumeric and underscores)

# Summary

Variable overrides provide flexible configuration management for E2E tests:

Method Best For Priority
Individual VARIABLE_* Secrets, specific overrides Highest
Comma-separated Simple key-values, quick overrides Medium
JSON format Complex values with special characters Medium

Choose the method that best fits your use case, and combine them when needed for maximum flexibility and security.