Setting Secrets for PR Branches
Is there a way to set a secret specifically for a supabase branch using the CLI? I don't see any options listed in the
secret set
documentation that mentions specifying a branch. I'm working on some CI/CD actions that use functions and it'd be really useful to be able to do this.4 Replies
See if this documentation might help https://supabase.com/docs/guides/deployment/branching/working-with-branches
Working with branches | Supabase Docs
Learn how to develop and manage your Supabase branches.
I have been looking at that, but it seems like the only way to reliably set secrets per-branch is by defining environment variables before the preview build happens.
Unfortunately I need to be able to set the secrets after the branch has been deployed. I have some other services that also build on-pr that rely on the supabase branch to build, which then generate some values after their build completes that need to be accessible by the edge functions within the branch.
what are these secrets for if you don't mind me asking as in could you set it for the edge functions on the branch after it's created or place it in vault?
So, turns out that the
--project-ref
option in the supabase CLI isn't used to point to the overarching "project" within supabase, but instead branch ids within that project.
So supabase secrets set MY_SECRET=$MY_SECRET --project-ref "$SUPABASE_BRANCH_ID"
sets the secret for that specific branch (and the overarching project id points to the main
branch).
The option's naming implies that it would only reference a specific project, not a branch, which isn't very explanatory, and also isn't documented here: https://supabase.com/docs/reference/cli/supabase-branches or here: https://supabase.com/docs/reference/cli/supabase-secrets. You might be able to infer this from looking at the example config.tomls here, but again, this behavior is not apparent that it would work in the CLI https://supabase.com/docs/guides/deployment/branching/configuration#feature-branch-configuration.CLI Reference | Supabase Docs
CLI reference for the Supabase CLI
CLI Reference | Supabase Docs
CLI reference for the Supabase CLI