2019-05-30 02:23:46 -04:00
---
type: reference
---
2018-09-09 23:56:04 -04:00
# Review Apps
2016-10-19 05:55:46 -04:00
2018-09-09 23:56:04 -04:00
> - [Introduced](https://gitlab.com/gitlab-org/gitlab-ce/issues/21971) in GitLab 8.12. Further additions were made in GitLab 8.13 and 8.14.
> - Inspired by [Heroku's Review Apps](https://devcenter.heroku.com/articles/github-integration-review-apps), which itself was inspired by [Fourchette](https://github.com/rainforestapp/fourchette).
2016-10-19 05:55:46 -04:00
2019-05-30 02:23:46 -04:00
Review Apps is a collaboration tool that takes the hard work out of providing an environment to showcase product changes.
2016-10-19 05:55:46 -04:00
2019-04-15 17:45:19 -04:00
## Introduction
2018-09-09 23:56:04 -04:00
Review Apps:
- Provide an automatic live preview of changes made in a feature branch by spinning up a dynamic environment for your merge requests.
2019-03-14 02:06:31 -04:00
- Allow designers and product managers to see your changes without needing to check out your branch and run your changes in a sandbox environment.
2019-03-10 21:47:01 -04:00
- Are fully integrated with the [GitLab DevOps LifeCycle ](../../README.md#the-entire-devops-lifecycle ).
2018-09-09 23:56:04 -04:00
- Allow you to deploy your changes wherever you want.
![Review Apps Workflow ](img/continuous-delivery-review-apps.svg )
2019-04-15 17:45:19 -04:00
In the above example:
2016-10-27 08:18:41 -04:00
2019-05-30 02:23:46 -04:00
- A Review App is built every time a commit is pushed to `topic branch` .
2019-04-15 17:45:19 -04:00
- The reviewer fails two reviews before passing the third review.
- Once the review as passed, `topic branch` is merged into `master` where it's deploy to staging.
- After been approved in staging, the changes that were merged into `master` are deployed in to production.
2016-10-27 09:31:06 -04:00
2019-04-15 17:45:19 -04:00
### How Review Apps work
A Review App is a mapping of a branch with an [environment ](../environments.md ).
Access to the Review App is made available as a link on the [merge request ](../../user/project/merge_requests.md ) relevant to the branch.
The following is an example of a merge request with an environment set dynamically.
2016-10-27 09:31:06 -04:00
![Review App in merge request ](img/review_apps_preview_in_mr.png )
2019-04-15 17:45:19 -04:00
In this example, a branch was:
2018-09-09 23:56:04 -04:00
- Successfully built.
- Deployed under a dynamic environment that can be reached by clicking on the **View app** button.
2019-04-15 17:45:19 -04:00
## Configuring Review Apps
2018-09-09 23:56:04 -04:00
2019-04-15 17:45:19 -04:00
Review Apps are built on [dynamic environments ](../environments.md#configuring-dynamic-environments ), which allow you to dynamically create a new environment for each branch.
2018-09-09 23:56:04 -04:00
2019-04-15 17:45:19 -04:00
The process of configuring Review Apps is as follows:
2016-10-27 08:18:41 -04:00
1. Set up the infrastructure to host and deploy the Review Apps.
2018-09-09 23:56:04 -04:00
1. [Install ](https://docs.gitlab.com/runner/install/ ) and [configure ](https://docs.gitlab.com/runner/commands/ ) a Runner to do deployment.
2019-04-03 11:40:01 -04:00
1. Set up a job in `.gitlab-ci.yml` that uses the [predefined CI environment variable ](../variables/README.md ) `${CI_COMMIT_REF_NAME}` to create dynamic environments and restrict it to run only on branches.
2018-09-09 23:56:04 -04:00
1. Optionally, set a job that [manually stops ](../environments.md#stopping-an-environment ) the Review Apps.
2016-10-27 08:18:41 -04:00
2019-04-15 17:45:19 -04:00
### Examples
2016-10-27 08:18:41 -04:00
2019-04-15 17:45:19 -04:00
The following are example projects that demonstrate Review App configuration:
2018-09-09 23:56:04 -04:00
- [NGINX ](https://gitlab.com/gitlab-examples/review-apps-nginx ).
- [OpenShift ](https://gitlab.com/gitlab-examples/review-apps-openshift ).
See also the video [Demo: Cloud Native Development with GitLab ](https://www.youtube.com/watch?v=jfIyQEwrocw ), which includes a Review Apps example.
2019-01-21 12:08:31 -05:00
2019-04-15 17:45:19 -04:00
### Route Maps
2019-01-21 12:08:31 -05:00
2019-04-15 17:45:19 -04:00
> Introduced in GitLab 8.17. In GitLab 11.5, the file links are available in the merge request widget.
2019-01-21 12:08:31 -05:00
Route Maps allows you to go directly from source files
to public pages on the [environment ](../environments.md ) defined for
2019-04-15 17:45:19 -04:00
Review Apps.
Once set up, the review app link in the merge request
2019-01-21 12:08:31 -05:00
widget can take you directly to the pages changed, making it easier
and faster to preview proposed modifications.
2019-04-15 17:45:19 -04:00
Configuring Route Maps involves telling GitLab how the paths of files
2019-01-21 12:08:31 -05:00
in your repository map to paths of pages on your website using a Route Map.
Once set, GitLab will display **View on ...** buttons, which will take you
to the pages changed directly from merge requests.
To set up a route map, add a a file inside the repository at `.gitlab/route-map.yml` ,
which contains a YAML array that maps `source` paths (in the repository) to `public`
paths (on the website).
2019-04-15 17:45:19 -04:00
#### Route Maps example
2019-01-21 12:08:31 -05:00
2019-04-15 17:45:19 -04:00
The following is an example of a route map for [Middleman ](https://middlemanapp.com ),
2019-01-21 12:08:31 -05:00
a static site generator (SSG) used to build [GitLab's website ](https://about.gitlab.com ),
deployed from its [project on GitLab.com ](https://gitlab.com/gitlab-com/www-gitlab-com ):
```yaml
# Team data
- source: 'data/team.yml' # data/team.yml
public: 'team/' # team/
# Blogposts
- source: /source\/posts\/([0-9]{4})-([0-9]{2})-([0-9]{2})-(.+?)\..*/ # source/posts/2017-01-30-around-the-world-in-6-releases.html.md.erb
public: '\1/\2/\3/\4/' # 2017/01/30/around-the-world-in-6-releases/
# HTML files
- source: /source\/(.+?\.html).*/ # source/index.html.haml
public: '\1' # index.html
# Other files
- source: /source\/(.*)/ # source/images/blogimages/around-the-world-in-6-releases-cover.png
public: '\1' # images/blogimages/around-the-world-in-6-releases-cover.png
```
2019-04-15 17:45:19 -04:00
Mappings are defined as entries in the root YAML array, and are identified by a `-` prefix. Within an entry, there is a hash map with two keys:
2019-01-21 12:08:31 -05:00
- `source`
2019-04-15 17:45:19 -04:00
- A string, starting and ending with `'` , for an exact match.
- A regular expression, starting and ending with `/` , for a pattern match:
- The regular expression needs to match the entire source path - `^` and `$` anchors are implied.
- Can include capture groups denoted by `()` that can be referred to in the `public` path.
- Slashes (`/`) can, but don't have to, be escaped as `\/` .
- Literal periods (`.`) should be escaped as `\.` .
- `public` , a string starting and ending with `'` .
- Can include `\N` expressions to refer to capture groups in the `source` regular expression in order of their occurrence, starting with `\1` .
2019-01-21 12:08:31 -05:00
The public path for a source path is determined by finding the first
`source` expression that matches it, and returning the corresponding
`public` path, replacing the `\N` expressions with the values of the
`()` capture groups if appropriate.
In the example above, the fact that mappings are evaluated in order
of their definition is used to ensure that `source/index.html.haml`
will match `/source\/(.+?\.html).*/` instead of `/source\/(.*)/` ,
and will result in a public path of `index.html` , instead of
`index.html.haml` .
2019-04-15 17:45:19 -04:00
Once you have the route mapping set up, it will take effect in the following locations:
2019-01-21 12:08:31 -05:00
2019-04-15 17:45:19 -04:00
- In the merge request widget. The:
- **View app** button will take you to the environment URL set in `.gitlab-ci.yml` .
- Dropdown will list the first 5 matched items from the route map, but you can filter them if more
than 5 are available.
2019-01-21 12:08:31 -05:00
![View app file list in merge request widget ](img/view_on_mr_widget.png )
- In the diff for a merge request, comparison, or commit.
!["View on env" button in merge request diff ](img/view_on_env_mr.png )
- In the blob file view.
!["View on env" button in file view ](img/view_on_env_blob.png )
2019-04-15 17:45:19 -04:00
## Working with Review Apps
After adding Review Apps to your workflow, you follow the branched Git flow. That is:
1. Push a branch and let the Runner deploy the Review App based on the `script` definition of the dynamic environment job.
1. Wait for the Runner to build and deploy your web application.
1. Click on the link that provided in the merge request related to the branch to see the changes live.
2019-06-14 08:32:47 -04:00
### Visual Reviews
2019-06-13 19:14:23 -04:00
2019-06-14 08:32:47 -04:00
The Visual Review feedback form can be added to a Review App to make it possible to post comments
2019-06-14 06:48:45 -04:00
directly from the app back to the merge request that spawned the Review App.
2019-06-14 08:32:47 -04:00
For example, a form like the following can be made to post the contents of the
2019-06-14 06:48:45 -04:00
text field into the discussion thread of a merge request:
2019-06-13 19:14:23 -04:00
2019-06-13 19:38:57 -04:00
![feedback form ](img/toolbar_feeback_form.png )
2019-06-13 19:14:23 -04:00
2019-06-14 08:32:47 -04:00
#### Using Visual Reviews
2019-06-13 19:14:23 -04:00
2019-06-14 14:23:43 -04:00
If Visual Reviews has been [enabled ](#configuring-visual-reviews ) for the Review App, the Visual Reviews feedback form is overlaid on the app's pages at the bottom-right corner.
To use the feedback form, you will need to create a [personal access token ](../../user/profile/personal_access_tokens.md ) with the API scope selected.
Paste the token into the feedback box, when prompted. If you select **Remember me** , your browser stores the token so that future visits to Review Apps at the same URL will not require you to re-enter the token. To clear the token, click **Log out** .
2019-06-13 19:14:23 -04:00
2019-06-14 06:48:45 -04:00
Comments can make use of all the [Markdown annotations ](../../user/markdown.md )
available in merge request comment boxes.
2019-06-13 19:14:23 -04:00
2019-06-14 08:32:47 -04:00
#### Configuring Visual Reviews
2019-06-13 19:14:23 -04:00
2019-06-14 08:32:47 -04:00
The feedback form is served through a script you add to pages in your Review App.
2019-06-14 14:23:43 -04:00
To access the code to include the script, click the **Review** button in the **Pipeline** section of the merge request.
2019-06-13 19:14:23 -04:00
2019-06-13 19:58:18 -04:00
![review button ](img/review_button.png )
![review modal ](img/review_modal.png )
2019-06-13 19:14:23 -04:00
2019-06-14 14:23:43 -04:00
The provided script hardcodes the project and merge request IDs. You may want to consider
using features of your programming language to use environment variables or other
2019-06-14 08:32:47 -04:00
means to inject these at runtime.
2019-06-14 06:48:45 -04:00
Future enhancements will make this process even easier.
2019-06-13 19:14:23 -04:00
2019-04-15 17:45:19 -04:00
## Limitations
Review App limitations are the same as [environments limitations ](../environments.md#limitations ).