Can I override Vercel system environment variables in GitHub Actions?

Vercel’s documentation mentions that only one custom environment variable can be overridden in the Pro plan. However, I need to override system environment variables specifically within my GitHub Actions workflow.

In my deployment setup, Vercel detects the branch and triggers an automatic release.

I know that using custom environment variables allows multiple values to be changed. However, I noticed that the API modifies original_environment and environment values.

Would it be possible to override these values to receive my desired environment configuration? If so, how can I achieve this?

// in preview 
        "original_environment": "Preview – project-name",
        "environment": "Preview – project-name,
// in production
        "original_environment": "Production – project-name",
        "environment": "Production – project-name,

Hi Jonghun!

Great question. You’ve touched on some important aspects of Vercel’s environment handling. Let me clarify a few points and suggest a workable solution:

  1. The Pro plan limitation you mentioned applies to custom environment variables, not system ones like original_environment and environment. These system variables are internal to Vercel and can’t be directly overridden, regardless of the plan.
  2. You’re correct that the API modifies original_environment and environment. This is by design and part of Vercel’s deployment process.
  3. Instead of trying to override these system values, you should:
    a) Use Vercel’s built-in environment detection
    b) Structure your application to handle environment-specific logic based on other available environment variables

Here’s an example of how you can achieve this in your GitHub Actions workflow:

name: Deploy to Vercel
on:
  push:
    branches: [main, staging]
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Deploy to Vercel
        env:
          VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
        run: |
          npx vercel --token ${VERCEL_TOKEN} \
                     --env APP_ENV=${GITHUB_REF##*/} \
                     --prod

This approach:

  1. Uses the GitHub ref to set a custom APP_ENV variable
  2. Deploys to Vercel using their CLI, which respects the automatic branch detection
  3. Allows you to use APP_ENV in your application to determine the environment, rather than relying on Vercel’s system variables

In your application code, you can then use APP_ENV (or VERCEL_ENV if you prefer Vercel’s built-in variable) to handle environment-specific logic.

Let us know how you get on!

Thank you for your response! However, it was slightly off-topic.

Here’s the exact issue I want to solve:
I’ve developed a GitHub Action that triggers when a deployment to dev or another feat branch is successfully completed.

However, due to Vercel’s nature,
when merging featdev and the deployment completes, two Preview deployments are created.
As a result, a single commit triggers two deployment notifications.

To address this, I considered using commit ref or SHA to determine a unique value,
but I couldn’t find a way to make it work (or maybe I’m missing something).

Additionally, this GitHub Action is not limited to Vercel notifications but is meant for general deployment notifications.

For reference, I am not considering using the Vercel CLI.

P.S.
I have confirmed that custom env works correctly and have tested it successfully.
However, even with the PRO plan, only one custom env can be used, which significantly limits its usefulness.
The difference in capacity between the PRO and Enterprise plans is too large.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.