Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some local env variables can't be set using netlify.toml #1805

Closed
culturestate opened this issue Sep 11, 2020 · 1 comment
Closed

Some local env variables can't be set using netlify.toml #1805

culturestate opened this issue Sep 11, 2020 · 1 comment
Labels
type: bug code to address defects in shipped code

Comments

@culturestate
Copy link

culturestate commented Sep 11, 2020

Describe the bug

For local plugin development, I need to access some Netlify environment variables that aren't provided by build - SITE_ID for API calls and DEPLOY_ID and BUILD_ID to generate a mock UI. Using dotenv to set these manually works as expected, but when I set them using netlify.toml, only SITE_ID is passed. This is semi-related to #1514.

I know these are described as read-only in the documentation, but:

  • I can set SITE_ID, so it seems like I should be able to set them all
  • It would be helpful if local environments could override these vars

Configuration

You can see the calls at https://github.com/quarva/netlify-plugin-sitrep/blob/master/index.js - builds are run using ntl build and an untracked local netlify.toml, configured as below.

envinfo

  System:
    OS: macOS 10.15.6
    CPU: (8) x64 Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
    Memory: 339.12 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.9.0 - ~/.nvm/versions/node/v14.9.0/bin/node
    Yarn: 1.22.5 - /usr/local/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v14.9.0/bin/npm
  npmPackages:
    @netlify/build: ^3.3.5 => 3.3.5 
  npmGlobalPackages:
    netlify-cli: 2.61.2

Logs
dotenv

.env

SITE_ID="SiteIDFromDotEnv"
BUILD_ID=BuildIDFromDotEnv
DEPLOY_ID=DeployIDFromDotEnv`

console.log(process.env)

 { ...
 SITE_ID: 'SiteIDFromDotEnv',
 BUILD_ID: 'BuildIDFromDotEnv',
 DEPLOY_ID: 'DeployIDFromDotEnv'
}

netlify.toml

netlify.toml

[build.environment]
SITE_ID="SiteIDFromNetlify.toml"
BUILD_ID="BuildIDFromNetlify.toml"
DEPLOY_ID="DeployIDFromNetlify.toml"

console.log(process.env)

{ ...
SITE_ID: 'SiteIDFromNetlify.toml',
... }

And for a sanity check:

console.log(SITE_ID + '-' + BUILD_ID + '-' + DEPLOY_ID);

SiteIDFromNetlify.toml-undefined-undefined
@culturestate culturestate added the type: bug code to address defects in shipped code label Sep 11, 2020
@culturestate
Copy link
Author

After looking at https://github.com/netlify/build/blob/master/packages/build/src/env/main.js I can see that this is expected behavior; the ability to set SITE_ID even though it's marked in the docs as a read-only variable threw me off.

With that in mind, I'll close this issue and hope for .env support in the future :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

1 participant