-`environment:name`, the first part is `review`, followed by a `/` and then `$CI_COMMIT_REF_NAME`,
-`environment:name`, the first part is `review`, followed by a `/` and then `$CI_COMMIT_REF_NAME`,
which takes the value of the branch name.
which receives the value of the branch name.
-`environment:url`, since `$CI_COMMIT_REF_NAME` itself may also contain `/`, or other characters that
-`environment:url`, we want a specific and distinct URL for each branch. `$CI_COMMIT_REF_NAME`
would be invalid in a domain name or URL, we use `$CI_ENVIRONMENT_SLUG` so that the environment can get a specific and distinct URL for each branch.
may contain a `/` or other characters that would be invalid in a domain name or URL,
so we use `$CI_ENVIRONMENT_SLUG` to get a "clean" or "safe" URL.
For example, given a `$CI_COMMIT_REF_NAME` of `100-Do-The-Thing`, the URL will be something
For example, given a `$CI_COMMIT_REF_NAME` of `100-Do-The-Thing`, the URL will be something
like `https://100-do-the-4f99a2.example.com`. Again, the way you set up
like `https://100-do-the-4f99a2.example.com`. Again, the way you set up
the web server to serve these requests is based on your setup.
the web server to serve these requests is based on your setup.
You could also use `$CI_COMMIT_REF_SLUG` in `environment:url`. For example, `https://$CI_COMMIT_REF_SLUG.example.com`.
We have used `$CI_ENVIRONMENT_SLUG` here because it is guaranteed to be unique. If
We have used `$CI_ENVIRONMENT_SLUG` here because it is guaranteed to be unique. If you're using a workflow like
you're using a workflow like [GitLab Flow](../workflow/gitlab_flow.md), collisions
[GitLab Flow](../workflow/gitlab_flow.md), collisions are unlikely and you may prefer environment names to be more closely based on the branch name. The example
are unlikely and you may prefer environment names to be more closely based on the
above would give you an URL like `https://100-do-the-thing.example.com`.
branch name. In that case, you could use `$CI_COMMIT_REF_SLUG` in `environment:url` in
the example above: `https://$CI_COMMIT_REF_SLUG.example.com`, which would give a URL
of `https://100-do-the-thing.example.com`.
NOTE: **Note:**
NOTE: **Note:**
You are not bound to use the same prefix or only slashes in the dynamic
You are not required to use the same prefix or only slashes (`/`) in the dynamic environments'
environments' names (`/`). However, this will enable the [grouping similar environments](#grouping-similar-environments) feature.
names. However, using this format will enable the [grouping similar environments](#grouping-similar-environments)
feature.
### Complete example
### Complete example
...
@@ -292,7 +294,7 @@ The configuration in this section provides a full development workflow where you
...
@@ -292,7 +294,7 @@ The configuration in this section provides a full development workflow where you
- Built.
- Built.
- Deployed as a Review App.
- Deployed as a Review App.
- Deployed to a staging server once the merge request is merged.
- Deployed to a staging server once the merge request is merged.
- Finally, manually deployed to the production server.
- Finally, able to be manually deployed to the production server.
The following combines the previous configuration examples, including:
The following combines the previous configuration examples, including:
...
@@ -348,8 +350,8 @@ deploy_prod:
...
@@ -348,8 +350,8 @@ deploy_prod:
-master
-master
```
```
A more realistic example would include copying files to a location where a
A more realistic example would also include copying files to a location where a
webserver (for example, NGINX) could then read and serve.
webserver (for example, NGINX) could then acess and serve them.
The example below will copy the `public` directory to `/srv/nginx/$CI_COMMIT_REF_SLUG/public`:
The example below will copy the `public` directory to `/srv/nginx/$CI_COMMIT_REF_SLUG/public`:
...
@@ -366,32 +368,33 @@ review_app:
...
@@ -366,32 +368,33 @@ review_app:
This example requires that NGINX and GitLab Runner are set up on the server this job will run on.
This example requires that NGINX and GitLab Runner are set up on the server this job will run on.
NOTE: **Note:**
NOTE: **Note:**
See the [limitations](#limitations) section for some edge cases regarding naming of your branches and Review Apps.
See the [limitations](#limitations) section for some edge cases regarding the naming of
your branches and Review Apps.
The complete example provides the following workflow for developers:
The complete example provides the following workflow to developers:
- Create a branch locally.
- Create a branch locally.
- Make changes and commit them
- Make changes and commit them.
- Push the branch to GitLab.
- Push the branch to GitLab.
- Create a merge request.
- Create a merge request.
Behind the scenes, GitLab runner will:
Behind the scenes, GitLab Runner will:
- Pick up the changes and start running the jobs.
- Pick up the changes and start running the jobs.
- Run the jobs sequentially as defined in `stages`:
- Run the jobs sequentially as defined in `stages`:
- First, run the tests.
- First, run the tests.
- If the tests succeed, build the app.
- If the tests succeed, build the app.
- If the build succeeds, the app will be is deployed to an environment with a name specific to the
- If the build succeeds, the app is deployed to an environment with a name specific to the
branch.
branch.
So now, every branch:
So now, every branch:
- Gets its own environment.
- Gets its own environment.
- Is deployed to its own location, with the added benefit of:
- Is deployed to its own unique location, with the added benefit of:
- Having a [history of deployments](#viewing-deployment-history).
- Having a [history of deployments](#viewing-deployment-history).
- Being able to [rollback changes](#retrying-and-rolling-back) if needed.
- Being able to [rollback changes](#retrying-and-rolling-back) if needed.
For more information on using the URL, see [Using the environment URL](#using-the-environment-url).
For more information, see [Using the environment URL](#using-the-environment-url).
### Protected environments
### Protected environments
...
@@ -401,11 +404,12 @@ For more information, see [Protected environments](environments/protected_enviro
...
@@ -401,11 +404,12 @@ For more information, see [Protected environments](environments/protected_enviro
## Working with environments
## Working with environments
Having configured environments, GitLab provides many features to work with them. These are documented below.
Once environments are configured, GitLab provides many features for working with them,
as documented below.
### Viewing environments and deployments
### Viewing environments and deployments
A list of environments and deployment statuses is available on project's **Operations > Environments** page.
A list of environments and deployment statuses is available on each project's **Operations > Environments** page.
For example:
For example:
...
@@ -416,11 +420,11 @@ This example shows:
...
@@ -416,11 +420,11 @@ This example shows:
- The environment's name with a link to its deployments.
- The environment's name with a link to its deployments.
- The last deployment ID number and who performed it.
- The last deployment ID number and who performed it.
- The job ID of the last deployment with its respective job name.
- The job ID of the last deployment with its respective job name.
- The commit information of the last deployment such as who committed, to what
- The commit information of the last deployment, such as who committed it, to what
branch, and the Git SHA of the commit.
branch, and the Git SHA of the commit.
- The exact time the last deployment was performed.
- The exact time the last deployment was performed.
- A button that takes you to the URL that you have defined under the
- A button that takes you to the URL that you defined under the `environment` keyword
`environment` keyword in `.gitlab-ci.yml`.
in `.gitlab-ci.yml`.
- A button that re-deploys the latest deployment, meaning it runs the job
- A button that re-deploys the latest deployment, meaning it runs the job
defined by the environment name for that specific commit.
defined by the environment name for that specific commit.
...
@@ -432,8 +436,8 @@ deployments, but an environment can have multiple deployments.
...
@@ -432,8 +436,8 @@ deployments, but an environment can have multiple deployments.
> - While you can create environments manually in the web interface, we recommend
> - While you can create environments manually in the web interface, we recommend
> that you define your environments in `.gitlab-ci.yml` first. They will
> that you define your environments in `.gitlab-ci.yml` first. They will
> be automatically created for you after the first deploy.
> be automatically created for you after the first deploy.
> - The environments page can only be viewed by Reporters and above. For more
> - The environments page can only be viewed by users with [Reporter permission](../user/permissions.md#project-members-permissions)
> information on the permissions, see the [permissions documentation](../user/permissions.md).
> and above. For more information on permissions, see the [permissions documentation](../user/permissions.md).
> - Only deploys that happen after your `.gitlab-ci.yml` is properly configured
> - Only deploys that happen after your `.gitlab-ci.yml` is properly configured
> will show up in the **Environment** and **Last deployment** lists.
> will show up in the **Environment** and **Last deployment** lists.
...
@@ -442,7 +446,7 @@ deployments, but an environment can have multiple deployments.
...
@@ -442,7 +446,7 @@ deployments, but an environment can have multiple deployments.
GitLab keeps track of your deployments, so you:
GitLab keeps track of your deployments, so you:
- Always know what is currently being deployed on your servers.
- Always know what is currently being deployed on your servers.
- Can have the full history of your deployments per every environment.
- Can have the full history of your deployments for every environment.
Clicking on an environment shows the history of its deployments. Here's an example **Environments** page
Clicking on an environment shows the history of its deployments. Here's an example **Environments** page
with multiple deployments:
with multiple deployments:
...
@@ -460,9 +464,9 @@ To retry or rollback a deployment:
...
@@ -460,9 +464,9 @@ To retry or rollback a deployment:
1. Navigate to **Operations > Environments**.
1. Navigate to **Operations > Environments**.
1. Click on the environment.
1. Click on the environment.
1.On the page that lists the deployment history for the environment, click the:
1.In the deployment history list for the environment, click the:
-**Rollback** button against a previously successful deployment, to roll back to that deployment.
-**Retry** button next to the last deployment, to retry that deployment.
-**Retry** button against the last deployment, to retry that deployment.
-**Rollback** button next to a previously successful deployment, to roll back to that deployment.
NOTE: **Note:**
NOTE: **Note:**
The defined deployment process in the job's `script` determines whether the rollback succeeds or not.
The defined deployment process in the job's `script` determines whether the rollback succeeds or not.
...
@@ -470,9 +474,7 @@ The defined deployment process in the job's `script` determines whether the roll
...
@@ -470,9 +474,7 @@ The defined deployment process in the job's `script` determines whether the roll
### Using the environment URL
### Using the environment URL
The [environment URL](yaml/README.md#environmenturl) is exposed in a few
The [environment URL](yaml/README.md#environmenturl) is exposed in a few
places within GitLab.
places within GitLab:
These are:
- In a merge request widget as a link:
- In a merge request widget as a link:
![Environment URL in merge request](img/environments_mr_review_app.png)
![Environment URL in merge request](img/environments_mr_review_app.png)
...
@@ -493,27 +495,28 @@ For example:
...
@@ -493,27 +495,28 @@ For example:
#### Going from source files to public pages
#### Going from source files to public pages
With GitLab's [Route Maps](review_apps/index.md#route-maps) you can go directly
With GitLab's [Route Maps](review_apps/index.md#route-maps) you can go directly
from source files to public pages on the environment set for Review Apps.
from source files to public pages in the environment set for Review Apps.
### Stopping an environment
### Stopping an environment
Stopping an environment:
Stopping an environment:
- Moves it from the list of **Available** environments to the list of **Stopped** environments on the [**Environments** page](#viewing-environments-and-deployments).
- Moves it from the list of **Available** environments to the list of **Stopped**
environments on the [**Environments** page](#viewing-environments-and-deployments).
- Executes an [`on_stop` action](yaml/README.md#environmenton_stop), if defined.
- Executes an [`on_stop` action](yaml/README.md#environmenton_stop), if defined.
This is often used when multiple developers are working on a project at the same time,
This is often used when multiple developers are working on a project at the same time,
each of them pushing to their own branches, causing many dynamic environments to be created.
each of them pushing to their own branches, causing many dynamic environments to be created.
NOTE: **Note:**
NOTE: **Note:**
Starting with GitLab 8.14, dynamic environments will be stopped automatically
Starting with GitLab 8.14, dynamic environments are stopped automatically
when their associated branch is deleted.
when their associated branch is deleted.
#### Automatically stopping an environment
#### Automatically stopping an environment
Environments can be stopped automatically using special configuration.
Environments can be stopped automatically using special configuration.
Consider the following example where the `deploy_review`calls the`stop_review`
Consider the following example where the `deploy_review`job calls`stop_review`
to clean up and stop the environment:
to clean up and stop the environment:
```yaml
```yaml
...
@@ -542,14 +545,14 @@ stop_review:
...
@@ -542,14 +545,14 @@ stop_review:
action:stop
action:stop
```
```
Setting the [`GIT_STRATEGY`](yaml/README.md#git-strategy) to `none` is necessary on the
Setting the [`GIT_STRATEGY`](yaml/README.md#git-strategy) to `none` is necessary in the
`stop_review` job so that the [GitLab Runner](https://docs.gitlab.com/runner/) won't try to check out the code
`stop_review` job so that the [GitLab Runner](https://docs.gitlab.com/runner/) won't
after the branch is deleted.
try to check out the code after the branch is deleted.
When you have an environment that has a stop action defined (typically when
When you have an environment that has a stop action defined (typically when
the environment describes a Review App), GitLab will automatically trigger a
the environment describes a Review App), GitLab will automatically trigger a
stop action when the associated branch is deleted. The `stop_review` job must
stop action when the associated branch is deleted. The `stop_review` job must
be in the same `stage` as the `deploy_review`one in order for the environment
be in the same `stage` as the `deploy_review`job in order for the environment
to automatically stop.
to automatically stop.
You can read more in the [`.gitlab-ci.yml` reference](yaml/README.md#environmenton_stop).
You can read more in the [`.gitlab-ci.yml` reference](yaml/README.md#environmenton_stop).
...
@@ -562,8 +565,8 @@ As documented in [Configuring dynamic environments](#configuring-dynamic-environ
...
@@ -562,8 +565,8 @@ As documented in [Configuring dynamic environments](#configuring-dynamic-environ
prepend environment name with a word, followed by a `/`, and finally the branch
prepend environment name with a word, followed by a `/`, and finally the branch
name, which is automatically defined by the `CI_COMMIT_REF_NAME` variable.
name, which is automatically defined by the `CI_COMMIT_REF_NAME` variable.
In short, environments that are named like `type/foo` are presented under a
In short, environments that are named like `type/foo` are all presented under the same
group named `type`.
group, named `type`.
In our [minimal example](#example-configuration), we named the environments `review/$CI_COMMIT_REF_NAME`
In our [minimal example](#example-configuration), we named the environments `review/$CI_COMMIT_REF_NAME`
where `$CI_COMMIT_REF_NAME` is the branch name. Here is a snippet of the example:
where `$CI_COMMIT_REF_NAME` is the branch name. Here is a snippet of the example:
...
@@ -588,13 +591,14 @@ exist, you should see something like:
...
@@ -588,13 +591,14 @@ exist, you should see something like:
>
>
> - For the monitoring dashboard to appear, you need to:
> - For the monitoring dashboard to appear, you need to:
> - Enable the [Prometheus integration](../user/project/integrations/prometheus.md).
> - Enable the [Prometheus integration](../user/project/integrations/prometheus.md).
> - Configure Prometheus to collect at least one [supported metric](../user/project/integrations/prometheus_library/index.md)
> - Configure Prometheus to collect at least one [supported metric](../user/project/integrations/prometheus_library/index.md).
> - With GitLab 9.2, all deployments to an environment are shown directly on the monitoring dashboard.
> - With GitLab 9.2, all deployments to an environment are shown directly on the monitoring dashboard.
If you have enabled [Prometheus for monitoring system and response metrics](../user/project/integrations/prometheus.md), you can monitor the performance behavior of your app running in each environment.
If you have enabled [Prometheus for monitoring system and response metrics](../user/project/integrations/prometheus.md),
you can monitor the behavior of your app running in each environment.
Once configured, GitLab will attempt to retrieve [supported performance metrics](../user/project/integrations/prometheus_library/index.md) for any
Once configured, GitLab will attempt to retrieve [supported performance metrics](../user/project/integrations/prometheus_library/index.md)
environment that has had a successful deployment. If monitoring data was
for any environment that has had a successful deployment. If monitoring data was
successfully retrieved, a **Monitoring** button will appear for each environment.
successfully retrieved, a **Monitoring** button will appear for each environment.
![Environment Detail with Metrics](img/deployments_view.png)
![Environment Detail with Metrics](img/deployments_view.png)
...
@@ -604,8 +608,8 @@ Clicking on the **Monitoring** button will display a new page showing up to the
...
@@ -604,8 +608,8 @@ Clicking on the **Monitoring** button will display a new page showing up to the
after initial deployment.
after initial deployment.
All deployments to an environment are shown directly on the monitoring dashboard,
All deployments to an environment are shown directly on the monitoring dashboard,
which allows easy correlation between any changes in performance and a new
which allows easy correlation between any changes in performance and new
Some GitLab [Enterprise Edition](https://about.gitlab.com/pricing/) features can behave differently for each
Some GitLab [Enterprise Edition](https://about.gitlab.com/pricing/) features can
environment. For example, you can [create a secret variable to be injected only into a production environment](https://docs.gitlab.com/ee/ci/variables/#limiting-environment-scopes-of-environment-variables-premium).
behave differently for each environment. For example, you can
[create a secret variable to be injected only into a production environment](https://docs.gitlab.com/ee/ci/variables/README.md#limiting-environment-scopes-of-environment-variables-premium).
In most cases, these features use the _environment specs_ mechanism, which offers
In most cases, these features use the _environment specs_ mechanism, which offers
an efficient way to implement scoping within each environment group.
an efficient way to implement scoping within each environment group.
...
@@ -696,9 +701,8 @@ In this case, `review/feature-1` spec takes precedence over `review/*` and `*` s
...
@@ -696,9 +701,8 @@ In this case, `review/feature-1` spec takes precedence over `review/*` and `*` s
## Limitations
## Limitations
You are limited to use only the [CI predefined variables](variables/README.md) in the
In the `environment: name`, you are limited to only the [predefined environment variables](variables/predefined_variables.md).
`environment: name`. If you try to re-use variables defined inside `script`
Re-using variables defined inside `script` as part of the environment name will not work.
as part of the environment name, it will not work.
## Further reading
## Further reading
...
@@ -707,3 +711,4 @@ Below are some links you may find interesting:
...
@@ -707,3 +711,4 @@ Below are some links you may find interesting:
-[The `.gitlab-ci.yml` definition of environments](yaml/README.md#environment)
-[The `.gitlab-ci.yml` definition of environments](yaml/README.md#environment)
-[A blog post on Deployments & Environments](https://about.gitlab.com/2016/08/26/ci-deployment-and-environments/)
-[A blog post on Deployments & Environments](https://about.gitlab.com/2016/08/26/ci-deployment-and-environments/)
-[Review Apps - Use dynamic environments to deploy your code for every branch](review_apps/index.md)
-[Review Apps - Use dynamic environments to deploy your code for every branch](review_apps/index.md)
-[Deploy Boards for your applications running on Kubernetes](https://docs.gitlab.com/ee/user/project/deploy_boards.html)**[PREMIUM]**