Validation Scripts

sfp-pro
sfp (community)

Availability

From

Aug 25 - 02

December 25

Validation scripts allow you to execute custom logic at specific points during the validation process. These global-level scripts provide hooks for setup, cleanup, reporting, and integration with external systems during validation workflows.

Validation Pipeline Execution

Configuration

Add script paths to your sfdx-project.json file:

{
  "plugins": {
    "sfp": {
      "validateScripts": {
        "preValidation": "./scripts/pre-validate.sh",
        "postValidation": "./scripts/post-validate.sh"
      }
    }
  }
}

Script Arguments

Scripts receive three arguments in this order:

  1. Context File Path - Absolute path to temporary JSON file containing validation context

  2. Target Org - Username of the target organization for validation

  3. Hub Org - Username of the hub organization (empty string "" if not available)

Context Data Structure

Pre-Validation Context

The context file contains information about packages ready for validation:

Post-Validation Context

The context file includes all pre-validation data plus validation results:

Example Scripts

Pre-Validation Script

Post-Validation Script

Error Handling & Behavior

Script Type
Failure Behavior
Timeout
Use Cases

Pre-validation

Halts validation process

30 minutes

Setup test data, configure environments, validate prerequisites

Post-validation

Logged as warning, validation continues

30 minutes

Cleanup resources, send notifications, generate reports

Best Practices

  • Make scripts executable: chmod +x scripts/pre-validate.sh

  • Use set -e: Exit on errors to ensure proper failure handling

  • Parse JSON safely: Use jq for reliable JSON parsing

  • Handle missing data: Check if fields exist before using them

  • Log clearly: Scripts appear in validation logs with CI/CD folding

  • Keep scripts fast: Remember the 30-minute timeout limit

  • Test locally: Validate script behavior before committing

Common Use Cases

Pre-Validation Scripts

  • Set up test data specific to validation scenarios

  • Configure external API endpoints for testing

  • Validate prerequisites (licenses, feature flags, etc.)

  • Initialize monitoring or logging for the validation process

Post-Validation Scripts

  • Clean up test data created during validation

  • Send notifications to Slack, Teams, or other systems

  • Generate custom reports or metrics

  • Update external tracking systems with validation results

  • Archive validation artifacts or logs

Last updated