How to Handle Multiline String Variables in Spacelift

Last updated: September 8, 2025

When working with multiline string variables in Spacelift (such as private keys or certificates), you'll need to use a specific approach to ensure the values are properly handled. The recommended method is to base64 encode the string and then decode it using a before_init hook.

Implementation Steps

  1. First, base64 encode your multiline string value

  2. Store the encoded value as a sensitive variable in the Spacelift UI

  3. Create a before_init hook to decode the value during runtime

Example Implementation

Here's a basic example of how to set this up in your runtime configuration:


before_init:
  - |
    echo $ENCODED_VALUE | base64 -d > decoded_file.key

For more details on runtime configuration and hooks, see our Runtime Configuration documentation.

Best Practices

  • Always use sensitive variables for storing encoded credentials or private keys

  • Verify your before_init hook works as expected by checking the decoded output

  • Consider implementing error handling in your hook script