netlify env:set and netlify link: Config in CI
netlify env:set writes a build environment variable for a site, and netlify link associates the current directory with that site.
Most netlify subcommands need to know which site they act on. In CI you supply NETLIFY_SITE_ID rather than linking, then set or import variables non-interactively.
What it does
netlify env:set KEY VALUE stores a variable for the site (optionally scoped to a deploy context with --context). netlify env:import loads many from a .env file. netlify link connects the working directory to a site by ID or name, writing .netlify/state.json.
Common usage
netlify link --id "$NETLIFY_SITE_ID" --auth "$NETLIFY_AUTH_TOKEN"
netlify env:set API_URL https://api.example.com --context production --auth "$NETLIFY_AUTH_TOKEN"
# bulk import from a dotenv file
netlify env:import .env.production --auth "$NETLIFY_AUTH_TOKEN"Options
| Command / flag | What it does |
|---|---|
| env:set KEY VALUE | Set one environment variable |
| env:import <file> | Import variables from a .env file |
| --context <ctx> | Scope to production, deploy-preview, or branch-deploy |
| link --id <site> | Link to a site by API ID |
| --auth <token> | Token auth (or NETLIFY_AUTH_TOKEN) |
| env:unset KEY | Remove a variable |
In CI
Export NETLIFY_AUTH_TOKEN and NETLIFY_SITE_ID so neither env:set nor link prompts. Linking is optional in CI: with NETLIFY_SITE_ID set, env commands resolve the site without .netlify/state.json on disk.
Common errors in CI
"Error: You don't appear to be in a folder that is linked to a site" means no link and no NETLIFY_SITE_ID; set the env var. "Error: Not authorized. Please set the NETLIFY_AUTH_TOKEN" means a missing or revoked token. A variable that does not take effect was usually set in the wrong --context.