netlify / netlify/cli

Deploy alias cannot find environment variables

Open
#6,898 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

type: bug
Dominant language
TypeScript
Stars
1.9k
Forks
474
Avg merge
23h 30m
Merged PRs (30d)
53

Description

Describe the bug

Hi, there. I have github action that deploys production branch to different alias upon release tag published event. For this alias deploy, I want to use environment variables that are different from my production or branch deployment.

github-action.yml

name: "Deploy POD"

on:
  release:
    types: ["published"]

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Repository checkout
        uses: actions/checkout@v4

      - name: Install Dependencies
        run: npm ci

      - name: Build project
        run: npm run build

      - name: Deploy to Netlify
        id: netlify_deploy
        run: |
          npx netlify deploy \
            --dir dist \
            --site ${{ secrets.NETLIFY_SITE_ID }} \
            --auth ${{ secrets.NETLIFY_API_TOKEN }} \
            --alias pod-1 \
            --message "Pod-1 deploy ${{ github.event.release.tag_name }}"

However, aliased deploy preview is not running properly because it is not reading any environment variable from my netlify site. I’ve tried to add env variables and specify deploy context as “branch deploys” and “custom branch” but both options have failed.

Is there a way to set environment variables for specific deploy alias?

My overall goal is to deploy new instance of production branch with its own environment variables without maintaining git branch

Steps to reproduce

Try to run following github action and check live URL

Configuration

No response

Environment

System:
OS: macOS 15.0.1
CPU: (12) arm64 Apple M2 Max
Memory: 109.33 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.11.0 - ~/.nvm/versions/node/v20.11.0/bin/node
npm: 10.2.4 - ~/.nvm/versions/node/v20.11.0/bin/npm
npmGlobalPackages:
netlify-cli: 17.37.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the github-action.yml example and reproduce the npx netlify deploy command using netlify-cli 17.37.0, focusing on --alias pod-1 and site environment variables. Trace the CLI's alias deploy and environment handling; done means confirming whether alias-specific variables are supported and documenting or testing the expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
github-actions, nodejs, typescript
Domain
cli, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.