Skip to content

Commit 401fec5

Browse files
lucleraystyfleleochibicodekodiakhq[bot]
authored
Update Environment Variables (#1748)
* update build step env variables section * add system env variables to git pages * fix amp error * add screenshot placeholders and finalize * add link in Project page * Update components/build-step-mdx/build-step.mdx Co-Authored-By: Steven <[email protected]> * remove examples * add Development Environment Variables * automatically -> optionally * update links to env vars section in build step * fix error * remove envs-and-secrets page and update links * update envs-and-secrets links * Update lib/data/v2/system-env-variables.js Co-Authored-By: Steven <[email protected]> * add link to envs section from serverless functions * Update components/build-step-mdx/build-step.mdx Co-Authored-By: Steven <[email protected]> * add screenshots * add `NOW_*` to reserved variable names * simplify deduping note * remove "\*\*" * improve descriptions of system env variables * fix screenshots * improve link to `now env` * Now Secrets -> Secrets * Update components/build-step-mdx/build-step.mdx Co-Authored-By: Leo Lamprecht <[email protected]> * Apply suggestions from code review Co-Authored-By: Leo Lamprecht <[email protected]> * Update components/build-step-mdx/build-step.mdx Co-Authored-By: Leo Lamprecht <[email protected]> * Update components/build-step-mdx/build-step.mdx Co-Authored-By: Leo Lamprecht <[email protected]> * Update components/build-step-mdx/build-step.mdx Co-Authored-By: Leo Lamprecht <[email protected]> * Apply suggestions from code review * Update components/build-step-mdx/build-step.mdx Co-authored-by: Steven <[email protected]> Co-authored-by: Leo Lamprecht <[email protected]> Co-authored-by: Shu Uesugi <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 3551b63 commit 401fec5

35 files changed

+443
-355
lines changed

components/build-step-mdx/build-step.mdx

+105-83
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@ import Caption from '~/components/text/caption'
44
import Note from '~/components/text/note'
55
import Card from '~/components/card'
66
import { InlineCode } from '~/components/text/code'
7+
import Strong from '~/components/text/strong'
78
import { Image } from '~/components/media'
89
import ProductName from '~/components/product-name'
9-
10-
When you trigger a deploy, <ProductName /> **builds** your project. For many frontend frameworks, <ProductName /> automatically configures the build settings, but you can also [customize](#customizing-build-settings) them. You can also use [environment variables](#using-environment-variables-and-secrets) to avoid hardcoding values.
10+
import { SYSTEM_ENVS } from '~/lib/data/v2/system-env-variables'
11+
import {
12+
Table,
13+
TableHead,
14+
TableBody,
15+
TableRow,
16+
TableRowCell,
17+
TableHeadCell
18+
} from '~/components/table'
19+
20+
When you trigger a deploy, <ProductName /> **builds** your project. For many frontend frameworks, <ProductName /> automatically configures the build settings, but you can also [customize](#customizing-build-settings) them. You can also use [environment variables](#environment-variables) to avoid hardcoding values.
1121

1222
## Customizing Build Settings
1323

@@ -32,7 +42,7 @@ Then, select the **Settings** tab:
3242
/>
3343
<Caption>Selecting the <b>Settings</b> tab from the Project Overview page.</Caption>
3444

35-
You can then edit the build settings from the **Build & Development Settings** and **Root Directory** sections.
45+
You can then edit the build settings from the **Build & Development Settings**, **Root Directory**, and **Environment Variables** sections.
3646

3747
### Build & Development Settings
3848

@@ -164,111 +174,123 @@ In cases like this, you can specify the project root directory. If you do so, pl
164174
deployment.
165175
</Note>
166176

167-
## Using Environment Variables and Secrets
168-
169-
When building your project, it may be necessary to use [environment variables](https://en.wikipedia.org/wiki/Environment_variable).
170-
171-
Adding environment variables requires two steps, defining the environment variable, then making it available to your projects' build step.
172-
173-
<Note>
174-
This section covers how to make environment variables available at{' '}
175-
<b>Build Time</b>, if you would like to make them available during{' '}
176-
<b>Run Time</b>, please see the{' '}
177-
<Link href="/docs/v2/serverless-functions/env-and-secrets/">
178-
Serverless Functions documentation
179-
</Link>
180-
.
181-
</Note>
182-
183-
### Adding Secrets
184-
185-
To define an environment variable, you should use **Now Secrets**. By using **Now Secrets**, the data will be encrypted and stored securely, no longer directly accessible by anyone, and only exposed to deployments as environment variables.
186-
187-
Adding **Now Secrets** can be done with [Now CLI](/download), providing three options to work with them.
188-
189-
<Note>
190-
When adding Now Secrets with Now CLI, the secret name is automatically
191-
lowercased before being stored.
192-
</Note>
193-
194-
To **define a Now Secret**, use the following command:
177+
## Environment Variables
195178

196-
<Snippet dark text="now secrets add <secret-name> <secret-value>"/>
197-
<Caption>Defining a <b>Now Secret</b> using <Link href="/now">Now CLI</Link>.</Caption>
179+
Environment Variables are accessible during both **Build Step** and **Runtime**, and can be configured for **Production**, **Preview**, and **Development** Environments individually.
198180

199-
To **remove a Now Secret**, use the following command:
181+
This allows you to include values that you don't want to share in your code or to change the behavior of your code depending on its Environment.
200182

201-
<Snippet dark text="now secrets rm <secret-name>"/>
202-
<Caption>Removing a <b>Now Secret</b> using <Link href="/now">Now CLI</Link>.</Caption>
183+
To declare an Environment Variable for your deployment, head to the **General** page of your **Project Settings** and locate the **Environment Variables** section.
203184

204-
To **rename a Now Secret**, use the following command:
185+
<Image
186+
src={`${process.env.ASSETS}/docs/build-step/env-vars-empty.png`}
187+
width={1488 / 2}
188+
height={824 / 2}
189+
shadow
190+
/>
191+
<Caption>The Environment Variables settings.</Caption>
205192

206-
<Snippet dark text="now secrets rename <secret-name> <new-name>"/>
207-
<Caption>Renaming a <b>Now Secret</b> using <Link href="/now">Now CLI</Link>.</Caption>
193+
First, choose between the following **Environments**:
208194

209-
### Providing Environment Variables
195+
| Environment | Description |
196+
| --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
197+
| **Production** | When selected, the Environment Variable will be applied to your next Production Deployment. To create a Production Deployment, push a commit to the default branch or run `now --prod`. |
198+
| **Preview** | The Environment Variable is applied to your next Preview Deployment. Preview Deployments are created when you push to a branch (for example, `my-new-feature`) or run `now`. |
199+
| **Development** | The Environment Variable is for use when running your project locally, with `now dev` or your preferred development command. To download Development Environment Variables, run `now env pull`. |
210200

211-
To provide your project with environment variables during the Build Step, you should create a `now.json` file like the one below:
201+
Enter the **Name** of the Environment Variable. For example, if you are using Node.js and you create an Environment Variable named `SENTRY_KEY`, it will be available under `process.env.SENTRY_KEY` in your code.
212202

213-
```json
214-
{
215-
"build": {
216-
"env": {
217-
"VARIABLE_NAME": "@secret-name"
218-
}
219-
}
220-
}
221-
```
203+
Then, enter the **Value** of the Environment Variable. The value is automatically encrypted and stored as a _Secret_ in our system when you click **Add**.
222204

223-
<Caption>
224-
An example <InlineCode>now.json</InlineCode> file that provides an
225-
application's build step with a defined environment variable.
226-
</Caption>
205+
<Image
206+
src={`${process.env.ASSETS}/docs/build-step/env-vars-user.png`}
207+
width={1488 / 2}
208+
height={632 / 2}
209+
shadow
210+
/>
211+
<Caption>Adding an Environment Variable in the Project Settings.</Caption>
227212

228-
When providing environment variables to your application, the value should always be prefixed with `@`, followed by the name of the [Now Secret](#adding-secrets) or environment variable name if using a `.env.build` file [during local development](#during-local-development).
213+
Once added, the Environment Variable is applied to your subsequent deployment.
214+
It can then be consumed during **Build Step** by the framework of your choice, or by a Serverless Function at **Runtime**.
229215

230-
To use the environment variable from inside the application you would need to reference it using the correct syntax for the language being used. For example, using Node.js, the syntax would be:
216+
<Note>
217+
If any Environment Variables differ between Deployments,{' '}
218+
<Link href="/docs/v2/platform/deployments#deduplication">deduplication</Link>{' '}
219+
will always be bypassed. For example, this means that merging to the default
220+
branch will no longer result in an instant deployment.
221+
</Note>
231222

232-
```
233-
process.env.VARIABLE_NAME
234-
```
223+
### Development Environment Variables
235224

236-
<Caption>
237-
Accessing a defined environment variable from within a Node.js application.
238-
</Caption>
225+
Environment Variables created for the Development Environment can be downloaded into a local development setup using the `now env pull` command provided by [Now CLI](/download):
239226

240-
Now, whenever the `process.env.VARIABLE_NAME` key is used, it will provide the application's build step with the value declared by the referenced **Now Secret**.
227+
<Snippet clipboard={false} dark text={`now env pull
228+
Downloading Development Environment Variables for project my-lovely-project
229+
✅ Created .env file [510ms]`} />
230+
<Caption>Downloading Development Environment Variables with `now env pull`.</Caption>
241231

242-
## During Local Development
232+
Running the command will create a `.env` file in your project folder. The `.env` file can then be consumed by `now dev` or
233+
your preferred development command.
243234

244-
When using `now dev` to develop your application locally if you require the use of [Serverless Functions](/docs/v2/serverless-functions/introduction), [Now Secrets](#adding-secrets) are not available. This is a security measure, to prevent accidental use of production secrets during development.
235+
Check out the [Now CLI reference](/docs/now-cli#commands/env) to learn more about `now env` commands.
245236

246-
To use environment variables during local development, create a `.env.build` file at the root of your project directory, for example:
237+
### Integration Environment Variables
247238

248-
```
249-
VARIABLE_NAME=variable_value
250-
```
239+
[Integrations](/integrations) can automatically add Environment Variables to your Project Settings.
240+
In that case, the Integration Configuration that added it will be displayed:
251241

252-
<Caption>
253-
An example <InlineCode>.env.build</InlineCode> file that provides the Build
254-
Step with a defined environment variable.
255-
</Caption>
242+
<Image
243+
src={`${process.env.ASSETS}/docs/build-step/env-vars-integration.png`}
244+
width={1488 / 2}
245+
height={728 / 2}
246+
shadow
247+
/>
248+
<Caption>Adding an Integration Environment Variable in the Project Settings.</Caption>
256249

257-
<Note type="warning">
258-
Usage of a <InlineCode>.env.build</InlineCode> file is only possible during
259-
local development and will not be made available when deploying for security
260-
reasons.
250+
<Note>
251+
Support for Integration Environment Variables was added on April 10th, 2020.
252+
Variables added before that date do not have the <Strong>Integration</Strong>{' '}
253+
indication.
261254
</Note>
262255

263-
### Updating Environment Variables
264-
265-
Environment variables are made available to the build step, meaning that they do not update in the application unless it is redeployed.
256+
### System Environment Variables
266257

267-
If you change the value of a [Now Secret](#adding-secrets) or environment variable and want your application to be aware of this, you should create a new deployment.
258+
ZEIT provides a set of Environment Variables that are optionally populated by the System, such as the URL of the Deployment or the name of the Git branch deployed.
268259

269-
### Reserved Variables
260+
To apply a System Environment Variable to your Deployment, enter its **Name**, leave the **Value** empty, and click **Add**.
270261

271-
The <ProductName /> platform reserves the usage of some environment variable names by default. You can find a list of these names in the [limits documentation](/docs/v2/platform/limits/#reserved-variables).
262+
<Image
263+
src={`${process.env.ASSETS}/docs/build-step/env-vars-system.png`}
264+
width={1488 / 2}
265+
height={632 / 2}
266+
shadow
267+
/>
268+
<Caption>Adding a System Environment Variable in the Project Settings.</Caption>
269+
270+
The following System Environment Variables are available:
271+
272+
<Table>
273+
<TableHead>
274+
<TableRow>
275+
<TableHeadCell className="head-cell">Name</TableHeadCell>
276+
<TableHeadCell className="head-cell">Description</TableHeadCell>
277+
</TableRow>
278+
</TableHead>
279+
<TableBody>
280+
{SYSTEM_ENVS.map(systemEnv => (
281+
<TableRow key={systemEnv.name}>
282+
<TableRowCell>
283+
<InlineCode>{systemEnv.name}</InlineCode>
284+
</TableRowCell>
285+
<TableRowCell>{systemEnv.description}</TableRowCell>
286+
</TableRow>
287+
))}
288+
</TableBody>
289+
</Table>
290+
291+
### Reserved Environment Variables
292+
293+
The <ProductName /> platform reserves the usage of some Environment Variable names by default. You can find a list of these names in the [limits documentation](/docs/v2/platform/limits/#reserved-variables).
272294

273295
## Ignored Files and Folders
274296

Original file line numberDiff line numberDiff line change
@@ -1,25 +1,36 @@
11
import Note from '~/components/text/note'
22
import Link from '~/components/text/link'
33
import ProductName from '~/components/product-name'
4+
import { BITBUCKET_SYSTEM_ENVS } from '~/lib/data/v2/system-env-variables'
5+
import { InlineCode } from '~/components/text/code'
6+
import {
7+
Table,
8+
TableHead,
9+
TableBody,
10+
TableRow,
11+
TableRowCell,
12+
TableHeadCell
13+
} from '~/components/table'
414

5-
You may want to use different workflows and APIs based on on Git information. To support this, <ProductName /> will deploy your app with the following built-in environment variables when deploying with <ProductName /> for Bitbucket.
6-
7-
<Note label="hint">
8-
These environment variables are available at both{' '}
9-
<Link href="/docs/v2/platform/glossary#run-time">Run Time</Link> and{' '}
10-
<Link href="/docs/v2/build-step">the Build Step</Link>.
11-
</Note>
15+
You may want to use different workflows and APIs based on Git information. To support this, the following [System Environment Variables](/docs/v2/build-step#system-environment-variables) can be added to your deployment:
1216

1317
<br />
1418

15-
| Variable Key | Description |
16-
| ------------------------------ | ---------------------------------------------------------------------------------- |
17-
| `BITBUCKET_DEPLOYMENT` | An indicator for whether the deployment was made by <ProductName /> for Bitbucket. |
18-
| `BITBUCKET_REPO_OWNER` | The Bitbucket user or team that the project belongs to. |
19-
| `BITBUCKET_REPO_SLUG` | The slug of the Bitbucket repository that was deployed. |
20-
| `BITBUCKET_REPO_NAME` | The name of the Bitbucket repository that was deployed. |
21-
| `BITBUCKET_COMMIT_REF` | The branch that the deployment was triggered by. |
22-
| `BITBUCKET_COMMIT_SHA` | The sha of the commit the deployment was triggered by. |
23-
| `BITBUCKET_COMMIT_MESSAGE` | The message accompanying the commit that was deployed. |
24-
| `BITBUCKET_COMMIT_AUTHOR_NAME` | The name of the commit author. |
25-
| `BITBUCKET_COMMIT_AUTHOR_URL` | Bitbucket profile URL of the commit author. |
19+
<Table>
20+
<TableHead>
21+
<TableRow noTagName>
22+
<TableHeadCell className="head-cell">Name</TableHeadCell>
23+
<TableHeadCell className="head-cell">Description</TableHeadCell>
24+
</TableRow>
25+
</TableHead>
26+
<TableBody>
27+
{BITBUCKET_SYSTEM_ENVS.map(systemEnv => (
28+
<TableRow key={systemEnv.name} noTagName>
29+
<TableRowCell>
30+
<InlineCode>{systemEnv.name}</InlineCode>
31+
</TableRowCell>
32+
<TableRowCell>{systemEnv.description}</TableRowCell>
33+
</TableRow>
34+
))}
35+
</TableBody>
36+
</Table>

components/git-mdx/github/default-behaviour.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ The latest push to any pull request will automatically be made available at a un
1818

1919
#### Deployment Authorizations for Forks
2020

21-
If you receive a pull request from a fork of your repository and there is either a change to the [`now.json`](/docs/configuration) file or there are [secrets](/docs/v2/serverless-functions/env-and-secrets#adding-secrets) used in your project; Now will require an authorization from you or a member of your team to deploy the pull request.
21+
If you receive a pull request from a fork of your repository and there is either a change to the [`now.json`](/docs/configuration) file or there are [Environment Variables](/docs/v2/build-step#environment-variables) used in your project; Now will require an authorization from you or a member of your team to deploy the pull request.
2222

2323
This behavior protects you and your project from a leak of sensitive information.

components/git-mdx/github/environment-variables.mdx

+28-18
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,35 @@ import { InlineCode } from '~/components/text/code'
33
import Note from '~/components/text/note'
44
import Link from '~/components/text/link'
55
import ProductName from '~/components/product-name'
6+
import { GITHUB_SYSTEM_ENVS } from '~/lib/data/v2/system-env-variables'
7+
import {
8+
Table,
9+
TableHead,
10+
TableBody,
11+
TableRow,
12+
TableRowCell,
13+
TableHeadCell
14+
} from '~/components/table'
615

7-
You may want to use different workflows and APIs based on Git information. To support this, <ProductName /> will deploy your app with the following built-in environment variables when deploying with <ProductName /> for GitHub.
8-
9-
<Note label="hint">
10-
These environment variables are available at both{' '}
11-
<Link href="/docs/v2/platform/glossary#run-time">Run Time</Link> and{' '}
12-
<Link href="/docs/v2/build-step">the Build Step</Link>.
13-
</Note>
16+
You may want to use different workflows and APIs based on Git information. To support this, the following [System Environment Variables](/docs/v2/build-step#system-environment-variables) can be added to your deployment:
1417

1518
<br />
1619

17-
| Variable Key | Description |
18-
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
19-
| `NOW_GITHUB_DEPLOYMENT` | An indicator for whether the app was deployed by <ProductName /> for GitHub. |
20-
| `NOW_GITHUB_ORG` | The GitHub organization that owns the repository the deployment is triggered from. |
21-
| `NOW_GITHUB_REPO` | The origin repository of the app. |
22-
| `NOW_GITHUB_COMMIT_ORG` | The organization of which the commit belongs. For example, when submitting a pull request from a forked repository. |
23-
| `NOW_GITHUB_COMMIT_REPO` | The repository of which the commit belongs. For example, when submitting a pull request from a forked repository. |
24-
| `NOW_GITHUB_COMMIT_REF` | The branch that the deployment was made from. |
25-
| `NOW_GITHUB_COMMIT_SHA` | The [sha](https://help.github.com/articles/github-glossary/#commit) of the commit the deployment was triggered by. |
26-
| `NOW_GITHUB_COMMIT_AUTHOR_LOGIN` | The username belonging to the author of the commit that the project was deployed by. |
27-
| `NOW_GITHUB_COMMIT_AUTHOR_NAME` | The name belonging to the author of the commit that the project was deployed by. |
20+
<Table>
21+
<TableHead>
22+
<TableRow noTagName>
23+
<TableHeadCell className="head-cell">Name</TableHeadCell>
24+
<TableHeadCell className="head-cell">Description</TableHeadCell>
25+
</TableRow>
26+
</TableHead>
27+
<TableBody>
28+
{GITHUB_SYSTEM_ENVS.map(systemEnv => (
29+
<TableRow key={systemEnv.name} noTagName>
30+
<TableRowCell>
31+
<InlineCode>{systemEnv.name}</InlineCode>
32+
</TableRowCell>
33+
<TableRowCell>{systemEnv.description}</TableRowCell>
34+
</TableRow>
35+
))}
36+
</TableBody>
37+
</Table>

0 commit comments

Comments
 (0)