Search code examples
typescriptgitlabcicd

Typescript doesn't read environment variables correctly in an aws cdk triggered from a gitlab ci


I add the variables here in the pipeline

variables:
    URL_ORIGIN: "url"

it echos successfully

script:
    - echo "URL_ORIGIN_VALUE $URL_ORIGIN"

but when I read it in typescript it is never defined

const urlOrigin = process.env["URL_ORIGIN"];

It needs to be an environment variable because it will change from environment to the other


Solution

  • I turns out when you need to read an environment variable in typescript. you must or it with a string or something. or it doesn't work.

    const urlOrigin = process.env["URL_ORIGIN"]|| 'not-defined';