Home > Software design >  End to end test suite can't retrieve env variables in Github Actions, but works fine in local
End to end test suite can't retrieve env variables in Github Actions, but works fine in local

Time:08-11

I am trying to set an environnement variable in Github Actions. It seems to be setup fine as I can display it using echo. Yet, my end-to-end suite doesn't run because:

EnvVarError: env-var: "JWT_SECRET" is a required variable, but it was not set

Which is a nice message displayed by a package I am recently using: enter image description here

The JWT secret is knowingly hardcoded and shared. I am going step by step, it will finally be removed and changed. It's in use for a pet side-project at the moment.

As we can see, github actions can set and display the env var. But can't make it available for the test suite.

Here is the workflow:

name: Tests

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:

  backend-tests:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: back
    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v2
      with:
        node-version: ${{ matrix.node-version }}
        cache: 'yarn'
        cache-dependency-path: '**/back/yarn.lock'
    - run: sudo /etc/init.d/mysql start
    - run: mysql -e 'CREATE DATABASE corposano' -uroot -proot
    - run: mysql -e 'ALTER USER 'root'@'localhost' IDENTIFIED BY ""' -uroot -proot
    - run: yarn
    - run: yarn build
    - run: yarn jest
    - run: yarn test:inte
      env:
        JWT_SECRET: MIIBO...
    - run: |
        JWT_SECRET=MIIBO...
        echo The JWT secret is:$JWT_SECRET
        yarn test:e2e

What did I miss to make it work?

CodePudding user response:

I believe it should be:

    - run: |
        export JWT_SECRET=MIIBO...
        echo The JWT secret is:$JWT_SECRET
        yarn test:e2e

or

    - run: |
        echo The JWT secret is:$JWT_SECRET
        yarn test:e2e
      env:
        JWT_SECRET: MIIBO...
  • Related