Created
March 22, 2025 16:30
-
-
Save sanjeed5/2b9e1b662f8d340adeed292110d306ed to your computer and use it in GitHub Desktop.
Upload all .env to Cloudflare Pages with one script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Script to automatically upload all environment variables from .env to Cloudflare Pages | |
| echo "Uploading environment variables to Cloudflare Pages project:" | |
| # Read each non-comment line from the .env file | |
| while IFS= read -r line || [[ -n "$line" ]]; do | |
| # Skip empty lines or comments | |
| if [[ -z "$line" || "$line" == \#* ]]; then | |
| continue | |
| fi | |
| # Extract variable name and value | |
| if [[ "$line" =~ ^([^=]+)=(.*)$ ]]; then | |
| varname="${BASH_REMATCH[1]}" | |
| varvalue="${BASH_REMATCH[2]}" | |
| # Remove quotes if present | |
| varvalue="${varvalue%\"}" | |
| varvalue="${varvalue#\"}" | |
| varvalue="${varvalue%\'}" | |
| varvalue="${varvalue#\'}" | |
| echo "Adding secret: $varname" | |
| # Use wrangler to set the secret | |
| echo "$varvalue" | wrangler pages secret put "$varname" --project-name | |
| fi | |
| done < .env | |
| echo "Environment variables upload complete!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment