Commit 3746d546 authored by Suzanne Selhorn's avatar Suzanne Selhorn Committed by Marcel Amirault

Clarified environment variables

Related to: https://gitlab.com/gitlab-org/gitlab/-/issues/300312
parent 0409b5fa
...@@ -2428,10 +2428,7 @@ Soon GitLab Runner picks up and starts the job. ...@@ -2428,10 +2428,7 @@ Soon GitLab Runner picks up and starts the job.
### `environment` ### `environment`
Use `environment` to define the [environment](../environments/index.md) that a job deploys to. Use `environment` to define the [environment](../environments/index.md) that a job deploys to.
If `environment` is specified and no environment under that name exists, a new For example:
one is created automatically.
In its simplest form, the `environment` keyword can be defined like:
```yaml ```yaml
deploy to production: deploy to production:
...@@ -2440,34 +2437,20 @@ deploy to production: ...@@ -2440,34 +2437,20 @@ deploy to production:
environment: production environment: production
``` ```
In the above example, the `deploy to production` job is marked as doing a You can assign a value to the `environment` keyword by using:
deployment to the `production` environment.
#### `environment:name`
The `environment: name` keyword can use any of the defined CI/CD [variables](#variables), - Plain text, like `production`.
including predefined, secure, or variables defined in the `.gitlab-ci.yml` file. - Variables, including CI/CD variables, predefined, secure, or variables
defined in the `.gitlab-ci.yml` file.
You can't use variables defined in a `script` section. You can't use variables defined in a `script` section.
The `environment` name can contain: If you specify an `environment` and no environment with that name exists,
an environment is created.
- letters
- digits
- spaces
- `-`
- `_`
- `/`
- `$`
- `{`
- `}`
Common names are `qa`, `staging`, and `production`, but you can use whatever #### `environment:name`
name works with your workflow.
Instead of defining the name of the environment right after the `environment` Set a name for an [environment](../environments/index.md). For example:
keyword, it's also possible to define it as a separate value. For that, use
the `name` keyword under `environment`:
```yaml ```yaml
deploy to production: deploy to production:
...@@ -2477,18 +2460,32 @@ deploy to production: ...@@ -2477,18 +2460,32 @@ deploy to production:
name: production name: production
``` ```
#### `environment:url` Common environment names are `qa`, `staging`, and `production`, but you can use any
name you want.
You can assign a value to the `name` keyword by using:
The `environment:url` keyword can use any of the defined CI/CD [variables](#variables), - Plain text, like `staging`.
including predefined, secure, or variables defined in the `.gitlab-ci.yml` file. - Variables, including CI/CD variables, predefined, secure, or variables
defined in the `.gitlab-ci.yml` file.
You can't use variables defined in a `script` section. You can't use variables defined in a `script` section.
This optional value exposes buttons that take you to the defined URL The environment `name` can contain:
In this example, if the job finishes successfully, it creates buttons - Letters
in the merge requests and in the environments/deployments pages that point - Digits
to `https://prod.example.com`. - Spaces
- `-`
- `_`
- `/`
- `$`
- `{`
- `}`
#### `environment:url`
Set a URL for an [environment](../environments/index.md). For example:
```yaml ```yaml
deploy to production: deploy to production:
...@@ -2499,6 +2496,17 @@ deploy to production: ...@@ -2499,6 +2496,17 @@ deploy to production:
url: https://prod.example.com url: https://prod.example.com
``` ```
After the job completes, you can access the URL by using a button in the merge request,
environment, or deployment pages.
You can assign a value to the `url` keyword by using:
- Plain text, like `https://prod.example.com`.
- Variables, including CI/CD variables, predefined, secure, or variables
defined in the `.gitlab-ci.yml` file.
You can't use variables defined in a `script` section.
#### `environment:on_stop` #### `environment:on_stop`
> - [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/22191) in GitLab 8.13. > - [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/22191) in GitLab 8.13.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment