Search code examples
amazon-web-servicesjenkinsgithub-actionsserverless-framework

How to use environment variables for serverless in GitHub Actions workflow?


I was trying to deploy serverless framework on AWS using GitHub Actions where I was previously using Jenkins.

Here is my workflow:

name: Deploy to Dev
on:
  workflow_dispatch:

jobs:
  Deploy-to-dev:
    runs-on: ubuntu-latest
    steps: 
      - name: Get code
        uses: actions/checkout@v4
      - name: Install NodeJs
        uses: actions/setup-node@v4
        with:
          node-version: 16
      - name: Install dependencies
        run: |
          npm install
          npm install -g serverless
      - uses: aws-actions/configure-aws-credentials@v3
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_NON_PROD }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_NON_PROD }}
          aws-region: us-east-1
      - name: Deploy to Serverless
        run: Environment=dev serverless deploy --stage dev

This is failing with error:

Cannot resolve serverless.yml: Variables resolution errored with:
  - Cannot resolve variable at "functions.xyz.environment.id": Value not found at "self" source,
  - Cannot resolve variable at "functions.xyz.environment.id": Value not found at "self" source
Error: Process completed with exit code 1.`

This was running fine from Jenkins:

Environment=$env_name serverless deploy --stage $env_name

I was passing $env_name from Jenkins parameter as dev.


Solution

  • Do

    - name: Deploy to Serverless
      run: |
         export Environment=dev 
         serverless deploy --stage dev