Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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: env-var
(might be related)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading