2019-05-30 02:23:46 -04:00
---
2020-05-19 23:08:04 -04:00
stage: Release
2020-12-01 10:09:28 -05:00
group: Release
2020-11-26 01:09:20 -05:00
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2019-05-30 02:23:46 -04:00
type: reference
---
2021-07-28 14:10:23 -04:00
# Review Apps **(FREE)**
2016-10-19 05:55:46 -04:00
2021-07-28 14:10:23 -04:00
Review Apps is a collaboration tool that assists with providing an environment to showcase product changes.
2016-10-19 05:55:46 -04:00
2021-02-17 13:09:19 -05:00
NOTE:
If you have a Kubernetes cluster, you can automate this feature in your applications
by using [Auto DevOps ](../../topics/autodevops/index.md ).
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.
2021-06-28 08:38:12 -04:00
- Are fully integrated with the [GitLab DevOps LifeCycle ](../../index.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 )
2021-07-28 14:10:23 -04:00
In the previous 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.
2021-03-01 16:11:09 -05:00
- After the review passes, `topic branch` is merged into the default branch, where it's deployed to staging.
- After its approval in staging, the changes that were merged into the default branch are deployed to production.
2016-10-27 09:31:06 -04:00
2019-07-08 09:44:42 -04:00
## How Review Apps work
2019-04-15 17:45:19 -04:00
2020-05-15 14:07:52 -04:00
A Review App is a mapping of a branch with an [environment ](../environments/index.md ).
2020-09-28 02:09:56 -04:00
Access to the Review App is made available as a link on the [merge request ](../../user/project/merge_requests/index.md ) relevant to the branch.
2019-04-15 17:45:19 -04:00
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.
2021-08-13 14:09:11 -04:00
- Deployed under a dynamic environment that can be reached by selecting **View app** .
2018-09-09 23:56:04 -04:00
2019-07-08 09:44:42 -04:00
After adding Review Apps to your workflow, you follow the branched Git flow. That is:
2020-09-13 23:09:21 -04:00
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.
2021-08-13 14:09:11 -04:00
1. To view the changes live, select the link in the merge request related to the branch.
2019-07-08 09:44:42 -04:00
2019-04-15 17:45:19 -04:00
## Configuring Review Apps
2018-09-09 23:56:04 -04:00
2021-03-03 19:11:19 -05:00
Review Apps are built on [dynamic environments ](../environments/index.md#create-a-dynamic-environment ), 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
2019-07-08 09:44:42 -04:00
1. Set up the infrastructure to host and deploy the Review Apps (check the [examples ](#review-apps-examples ) below).
2020-09-13 23:09:21 -04:00
1. [Install ](https://docs.gitlab.com/runner/install/ ) and [configure ](https://docs.gitlab.com/runner/commands/ ) a runner to do deployment.
2021-09-09 23:10:59 -04:00
1. Set up a job in `.gitlab-ci.yml` that uses the [predefined CI/CD variable ](../variables/index.md ) `${CI_COMMIT_REF_SLUG}`
2020-02-14 13:08:45 -05:00
to create dynamic environments and restrict it to run only on branches.
Alternatively, you can get a YML template for this job by [enabling review apps ](#enable-review-apps-button ) for your project.
2021-08-11 05:10:00 -04:00
1. Optionally, set a job that [manually stops ](../environments/index.md#stop-an-environment ) the Review Apps.
2016-10-27 08:18:41 -04:00
2020-02-14 13:08:45 -05:00
### Enable Review Apps button
2020-05-20 23:08:00 -04:00
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/118844) in GitLab 12.8.
2020-02-14 13:08:45 -05:00
2021-08-13 14:09:11 -04:00
When configuring Review Apps for a project, you add a new job to the `.gitlab-ci.yml` file,
as mentioned above. To facilitate this, and if you are using Kubernetes, you can select
**Enable Review Apps** and GitLab prompts you with a template code block that
you can copy and paste into `.gitlab-ci.yml` as a starting point.
2020-02-14 13:08:45 -05:00
2021-08-13 14:09:11 -04:00
Prerequisite:
- You need at least the Developer [role ](../../user/permissions.md ) for the project.
To use the Review Apps template:
1. On the top bar, select **Menu > Projects** and find the project you want to create a Review App job for.
1. On the left sidebar, select **Deployments > Environments** .
1. Select **Enable Review Apps** .
2020-02-14 13:08:45 -05:00
1. Copy the provided code snippet and paste it into your
`.gitlab-ci.yml` file:
![Enable Review Apps modal ](img/enable_review_app_v12_8.png )
2021-08-13 14:09:11 -04:00
You can edit this template as needed.
2020-02-14 13:08:45 -05:00
2020-02-17 19:09:20 -05:00
## Review Apps auto-stop
2021-03-03 19:11:19 -05:00
See how to [configure Review Apps environments to expire and auto-stop ](../environments/index.md#stop-an-environment-after-a-certain-time-period )
2020-02-17 19:09:20 -05:00
after a given period of time.
2019-07-08 09:44:42 -04:00
## Review Apps 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 ).
2020-06-09 02:08:43 -04:00
Other examples of Review Apps:
- < i class = "fa fa-youtube-play youtube" aria-hidden = "true" ></ i >
[Cloud Native Development with GitLab ](https://www.youtube.com/watch?v=jfIyQEwrocw ).
- [Review Apps for Android ](https://about.gitlab.com/blog/2020/05/06/how-to-create-review-apps-for-android-with-gitlab-fastlane-and-appetize-dot-io/ ).
2019-01-21 12:08:31 -05:00
2019-07-08 09:44:42 -04:00
## Route Maps
2019-01-21 12:08:31 -05:00
Route Maps allows you to go directly from source files
2020-05-15 14:07:52 -04:00
to public pages on the [environment ](../environments/index.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.
2020-12-17 16:09:57 -05:00
Once set, GitLab displays **View on ...** buttons, which take you
2019-01-21 12:08:31 -05:00
to the pages changed directly from merge requests.
2019-11-18 22:06:07 -05:00
To set up a route map, add a file inside the repository at `.gitlab/route-map.yml` ,
2019-01-21 12:08:31 -05:00
which contains a YAML array that maps `source` paths (in the repository) to `public`
paths (on the website).
2019-07-08 09:44:42 -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 ),
2020-12-15 19:09:58 -05:00
a static site generator (SSG) used to build the [GitLab website ](https://about.gitlab.com ),
2019-01-21 12:08:31 -05:00
deployed from its [project on GitLab.com ](https://gitlab.com/gitlab-com/www-gitlab-com ):
```yaml
# Team data
2020-09-08 14:08:48 -04:00
- source: 'data/team.yml' # data/team.yml
public: 'team/' # team/
2019-01-21 12:08:31 -05:00
# Blogposts
2020-09-08 14:08:48 -04:00
- 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/
2019-01-21 12:08:31 -05:00
# HTML files
2020-09-08 14:08:48 -04:00
- source: /source\/(.+?\.html).*/ # source/index.html.haml
public: '\1' # index.html
2019-01-21 12:08:31 -05:00
# Other files
2020-09-08 14:08:48 -04:00
- 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-01-21 12:08:31 -05:00
```
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`
2020-12-17 16:09:57 -05:00
matches `/source\/(.+?\.html).*/` instead of `/source\/(.*)/` ,
and results in a public path of `index.html` , instead of
2019-01-21 12:08:31 -05:00
`index.html.haml` .
2020-12-17 16:09:57 -05:00
After you have the route mapping set up, it takes effect in the following locations:
2019-01-21 12:08:31 -05:00
2021-08-13 14:09:11 -04:00
- In the merge request widget:
- The **View app** button takes you to the environment URL set in the `.gitlab-ci.yml` file.
- The list shows the first 5 matched items from the route map, but you can filter them if more
2019-04-15 17:45:19 -04:00
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.
2021-01-22 19:08:46 -05:00
![View on environment button in merge request diff ](img/view_on_env_mr.png )
2019-01-21 12:08:31 -05:00
- In the blob file view.
2021-01-22 19:08:46 -05:00
![View on environment button in file view ](img/view_on_env_blob.png )
2019-04-15 17:45:19 -04:00
2021-01-27 07:09:01 -05:00
## Visual Reviews **(PREMIUM)**
2019-06-13 19:14:23 -04:00
2021-01-27 07:09:01 -05:00
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/10761) in GitLab 12.0.
> - [Moved](https://about.gitlab.com/blog/2021/01/26/new-gitlab-product-subscription-model/) to GitLab Premium in 13.9.
2020-09-30 02:09:47 -04:00
> - It's [deployed behind a feature flag](../../user/feature_flags.md), enabled by default.
> - It's enabled on GitLab.com.
2021-01-27 07:09:01 -05:00
> - For GitLab self-managed instances, GitLab administrators can opt to [disable it](#enable-or-disable-visual-reviews). **(PREMIUM SELF)**
2019-06-17 09:19:20 -04:00
2020-09-30 02:09:47 -04:00
With Visual Reviews, members of any team (Product, Design, Quality, and so on) can provide feedback comments through a form in your review apps. The comments are added to the merge request that triggered the review app.
2019-06-14 06:48:45 -04:00
2020-09-30 02:09:47 -04:00
### Using Visual Reviews
2019-06-13 19:14:23 -04:00
2020-09-30 02:09:47 -04:00
After Visual Reviews has been [configured ](#configure-review-apps-for-visual-reviews ) for the
Review App, the Visual Reviews feedback form is overlaid on the right side of every page.
2019-11-21 19:06:08 -05:00
2020-09-30 02:09:47 -04:00
![Visual review feedback form ](img/toolbar_feedback_form_v13_5.png )
To use the feedback form to make a comment in the merge request:
2021-08-13 14:09:11 -04:00
1. On the right side of a page, select the **Review** tab.
2020-09-30 02:09:47 -04:00
1. Make a comment on the visual review. You can make use of all the
[Markdown annotations ](../../user/markdown.md ) that are also available in
merge request comments.
1. Enter your personal information:
- If [`data-require-auth` ](#authentication-for-visual-reviews ) is `true` , you must enter your [personal access token ](../../user/profile/personal_access_tokens.md ).
- Otherwise, enter your name, and optionally your email.
2021-08-13 14:09:11 -04:00
1. Select **Send feedback** .
2020-09-30 02:09:47 -04:00
< i class = "fa fa-youtube-play youtube" aria-hidden = "true" > < / i >
To see Visual reviews in action, see the [Visual Reviews Walk through ](https://youtu.be/1_tvWTlPfM4 ).
### Configure Review Apps for Visual Reviews
2019-11-21 19:06:08 -05:00
2019-07-08 09:44:42 -04:00
The feedback form is served through a script you add to pages in your Review App.
2021-07-27 23:08:41 -04:00
It should be added to the `<head>` of your application and
2020-09-30 02:09:47 -04:00
consists of some project and merge request specific values. Here's how it
looks for a project with code hosted in a project on GitLab.com:
2019-07-08 09:44:42 -04:00
```html
< script
data-project-id='11790219'
data-merge-request-id='1'
2020-09-30 02:09:47 -04:00
data-mr-url='https://gitlab.com'
2019-07-08 09:44:42 -04:00
data-project-path='sarah/review-app-tester'
2020-04-16 05:09:37 -04:00
data-require-auth='true'
2019-07-08 09:44:42 -04:00
id='review-app-toolbar-script'
2020-09-30 02:09:47 -04:00
src='https://gitlab.com/assets/webpack/visual_review_toolbar.js'>
2019-07-08 09:44:42 -04:00
< / script >
```
2019-06-14 14:23:43 -04:00
2021-02-16 13:09:24 -05:00
Ideally, you should use [CI/CD variables ](../variables/predefined_variables.md )
2019-07-08 09:44:42 -04:00
to replace those values at runtime when each review app is created:
- `data-project-id` is the project ID, which can be found by the `CI_PROJECT_ID`
variable.
- `data-merge-request-id` is the merge request ID, which can be found by the
`CI_MERGE_REQUEST_IID` variable. `CI_MERGE_REQUEST_IID` is available only if
2021-06-29 14:07:04 -04:00
[`only: [merge_requests]`](../pipelines/merge_request_pipelines.md)
2019-07-08 09:44:42 -04:00
is used and the merge request is created.
2020-12-17 16:09:57 -05:00
- `data-mr-url` is the URL of the GitLab instance and is the same for all
2019-07-08 09:44:42 -04:00
review apps.
- `data-project-path` is the project's path, which can be found by `CI_PROJECT_PATH` .
2020-12-17 16:09:57 -05:00
- `data-require-auth` is optional for public projects but required for [private and internal ones ](#authentication-for-visual-reviews ). If this is set to `true` , the user is required to enter their [personal access token ](../../user/profile/personal_access_tokens.md ) instead of their name and email.
2019-07-08 09:44:42 -04:00
- `id` is always `review-app-toolbar-script` , you don't need to change that.
- `src` is the source of the review toolbar script, which resides in the
2020-12-17 16:09:57 -05:00
respective GitLab instance and is the same for all review apps.
2019-07-08 09:44:42 -04:00
2020-09-30 02:09:47 -04:00
For example, in a Ruby application with code hosted on in a project GitLab.com, you would need to have this script:
2019-07-08 09:44:42 -04:00
```html
< script
data-project-id="ENV['CI_PROJECT_ID']"
data-merge-request-id="ENV['CI_MERGE_REQUEST_IID']"
2020-09-30 02:09:47 -04:00
data-mr-url='https://gitlab.com'
2019-07-08 09:44:42 -04:00
data-project-path="ENV['CI_PROJECT_PATH']"
id='review-app-toolbar-script'
2020-09-30 02:09:47 -04:00
src='https://gitlab.com/assets/webpack/visual_review_toolbar.js'>
2019-07-08 09:44:42 -04:00
< / script >
```
2019-06-14 14:23:43 -04:00
2019-07-08 09:44:42 -04:00
Then, when your app is deployed via GitLab CI/CD, those variables should get
replaced with their real values.
2019-06-13 19:14:23 -04:00
2019-11-21 19:06:08 -05:00
### Determining merge request ID
The visual review tools retrieve the merge request ID from the `data-merge-request-id`
data attribute included in the `script` HTML tag used to add the visual review tools
to your review app.
2021-03-12 13:09:23 -05:00
After determining the ID for the merge request to link to a visual review app, you
can supply the ID by either:
2019-11-21 19:06:08 -05:00
2020-05-04 14:10:20 -04:00
- Hard-coding it in the script tag via the data attribute `data-merge-request-id` of the app.
2019-11-21 19:06:08 -05:00
- Dynamically adding the `data-merge-request-id` value during the build of the app.
- Supplying it manually through the visual review form in the app.
2021-01-27 07:09:01 -05:00
### Enable or disable Visual Reviews **(PREMIUM SELF)**
2020-04-16 05:09:37 -04:00
2020-09-30 02:09:47 -04:00
Visual Reviews is deployed behind a feature flag that is **enabled by default** .
[GitLab administrators with access to the GitLab Rails console ](../../administration/feature_flags.md )
can opt to disable it.
2020-04-16 05:09:37 -04:00
2020-09-30 02:09:47 -04:00
To disable it:
2020-04-16 05:09:37 -04:00
2020-09-30 02:09:47 -04:00
```ruby
Feature.disable(:anonymous_visual_review_feedback)
```
2019-06-13 19:14:23 -04:00
2020-09-30 02:09:47 -04:00
To enable it:
2019-06-13 19:14:23 -04:00
2020-09-30 02:09:47 -04:00
```ruby
Feature.enable(:anonymous_visual_review_feedback)
```
2019-06-13 19:14:23 -04:00
2020-09-30 02:09:47 -04:00
### Authentication for Visual Reviews
2019-07-08 09:44:42 -04:00
2020-09-30 02:09:47 -04:00
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/42750#note_317271120) in GitLab 12.10.
To enable visual reviews for private and internal projects, set the
[`data-require-auth` variable ](#enable-or-disable-visual-reviews ) to `true` . When enabled,
the user must enter a [personal access token ](../../user/profile/personal_access_tokens.md )
with `api` scope before submitting feedback.
2019-06-13 19:14:23 -04:00
2020-09-30 02:09:47 -04:00
This same method can be used to require authentication for any public projects.