Workflow not reading my environment variables

I’m encountering difficulties while trying to utilize environment variables in my GitHub Actions workflow, particularly when working with Vite as my development environment for a React web application. I’ve correctly configured my secrets in GitHub and referenced these environment variables in my GitHub Actions YAML file and Vite configuration. However, it appears that some variables are not being passed correctly.

I’ve defined the following necessary environment variables (VITE_EMAIL_SERVICE, VITE_EMAIL_TEMPLATE, VITE_EMAIL_SERVICE_KEY) in the build step of my workflow.

While secrets.GITHUB_TOKEN is accessed correctly in the workflow, the variables VITE_EMAIL_SERVICE, VITE_EMAIL_TEMPLATE, and VITE_EMAIL_SERVICE_KEY don’t seem to be properly passed to my application during build and deployment. I’ve added debugging steps to print all available environment variables in GitHub Actions, and I’ve confirmed that these specific variables are either missing or do not contain the expected values.

What could be the reasons behind these environment variables not being passed correctly in my workflow? What additional configurations should I consider in my GitHub Actions YAML file or in my Vite setup to ensure that environment variables are handled correctly?

.env:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>VITE_EMAIL_TEMPLATE = "example"
VITE_EMAIL_SERVICE = "example"
VITE_EMAIL_SERVICE_KEY = "example"
</code>
<code>VITE_EMAIL_TEMPLATE = "example" VITE_EMAIL_SERVICE = "example" VITE_EMAIL_SERVICE_KEY = "example" </code>
VITE_EMAIL_TEMPLATE = "example"
VITE_EMAIL_SERVICE = "example"
VITE_EMAIL_SERVICE_KEY = "example"

deploy.yaml:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>name: Deploy
on:
push:
branches:
- main
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
- name: Install dependencies
uses: bahmutov/npm-install@v1
- name: Print environment variables
env:
VITE_EMAIL_SERVICE: ${{ secrets.VITE_EMAIL_SERVICE }}
VITE_EMAIL_TEMPLATE: ${{ secrets.VITE_EMAIL_TEMPLATE }}
VITE_EMAIL_SERVICE_KEY: ${{ secrets.VITE_EMAIL_SERVICE_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "VITE_EMAIL_SERVICE=$VITE_EMAIL_SERVICE"
echo "VITE_EMAIL_TEMPLATE=$VITE_EMAIL_TEMPLATE"
echo "VITE_EMAIL_SERVICE_KEY=$VITE_EMAIL_SERVICE_KEY"
echo "GITHUBTOKEN=$GITHUB_TOKEN"
- name: Build project
run: npm run build
env:
VITE_EMAIL_SERVICE: ${{ secrets.VITE_EMAIL_SERVICE }}
VITE_EMAIL_TEMPLATE: ${{ secrets.VITE_EMAIL_TEMPLATE }}
VITE_EMAIL_SERVICE_KEY: ${{ secrets.VITE_EMAIL_SERVICE_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload production-ready build files
uses: actions/upload-artifact@v3
with:
name: production-files
path: ./dist
deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: production-files
path: ./dist
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
</code>
<code>name: Deploy on: push: branches: - main jobs: build: name: Build runs-on: ubuntu-latest steps: - name: Checkout repo uses: actions/checkout@v3 - name: Setup Node uses: actions/setup-node@v3 - name: Install dependencies uses: bahmutov/npm-install@v1 - name: Print environment variables env: VITE_EMAIL_SERVICE: ${{ secrets.VITE_EMAIL_SERVICE }} VITE_EMAIL_TEMPLATE: ${{ secrets.VITE_EMAIL_TEMPLATE }} VITE_EMAIL_SERVICE_KEY: ${{ secrets.VITE_EMAIL_SERVICE_KEY }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | echo "VITE_EMAIL_SERVICE=$VITE_EMAIL_SERVICE" echo "VITE_EMAIL_TEMPLATE=$VITE_EMAIL_TEMPLATE" echo "VITE_EMAIL_SERVICE_KEY=$VITE_EMAIL_SERVICE_KEY" echo "GITHUBTOKEN=$GITHUB_TOKEN" - name: Build project run: npm run build env: VITE_EMAIL_SERVICE: ${{ secrets.VITE_EMAIL_SERVICE }} VITE_EMAIL_TEMPLATE: ${{ secrets.VITE_EMAIL_TEMPLATE }} VITE_EMAIL_SERVICE_KEY: ${{ secrets.VITE_EMAIL_SERVICE_KEY }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Upload production-ready build files uses: actions/upload-artifact@v3 with: name: production-files path: ./dist deploy: name: Deploy needs: build runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' steps: - name: Download artifact uses: actions/download-artifact@v3 with: name: production-files path: ./dist - name: Deploy to GitHub Pages uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./dist </code>
name: Deploy

on:
  push:
    branches:
      - main

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repo
        uses: actions/checkout@v3

      - name: Setup Node
        uses: actions/setup-node@v3

      - name: Install dependencies
        uses: bahmutov/npm-install@v1

      - name: Print environment variables
        env:
          VITE_EMAIL_SERVICE: ${{ secrets.VITE_EMAIL_SERVICE }}
          VITE_EMAIL_TEMPLATE: ${{ secrets.VITE_EMAIL_TEMPLATE }}
          VITE_EMAIL_SERVICE_KEY: ${{ secrets.VITE_EMAIL_SERVICE_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
            echo "VITE_EMAIL_SERVICE=$VITE_EMAIL_SERVICE"
            echo "VITE_EMAIL_TEMPLATE=$VITE_EMAIL_TEMPLATE"
            echo "VITE_EMAIL_SERVICE_KEY=$VITE_EMAIL_SERVICE_KEY"
            echo "GITHUBTOKEN=$GITHUB_TOKEN"

      - name: Build project
        run: npm run build
        env:
          VITE_EMAIL_SERVICE: ${{ secrets.VITE_EMAIL_SERVICE }}
          VITE_EMAIL_TEMPLATE: ${{ secrets.VITE_EMAIL_TEMPLATE }}
          VITE_EMAIL_SERVICE_KEY: ${{ secrets.VITE_EMAIL_SERVICE_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Upload production-ready build files
        uses: actions/upload-artifact@v3
        with:
          name: production-files
          path: ./dist

  deploy:
    name: Deploy
    needs: build
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/main'

    steps:
      - name: Download artifact
        uses: actions/download-artifact@v3
        with:
          name: production-files
          path: ./dist

      - name: Deploy to GitHub Pages
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./dist

GitHub environment variables:
enter image description here

I tried to deploy on my git-pages but env variables does not assign on my “deploy.yaml”, at the echo of these variables they are empty. But “${{ secrets.GITHUB_TOKEN }}” goes correctly

New contributor

jrwithahoodie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật