The Now for GitLab integration automatically deploys and aliases your GitLab projects with Now.

Now for GitLab provides:

  • Automatic deployments for every push to branches and merge requests to preview changes live.
  • Aliases for the most recent changes from the default branch.
  • Instant rollbacks when reverting changes that have already been aliased.

A deployment from a Now for GitLab push.

Set up Now for GitLab

Step 1: Link Now to Your GitLab Account

You can connect your Now account to GitLab by visiting your account or team settings page and clicking the "Connect with GitLab" button.

The Now for GitLab installation section within the account or team general settings page.

Next, you will need to authorize the Now application on GitLab with your account.

Once authorized, you will be redirected back to your ZEIT account or team settings page.

Step 2: Link GitLab Projects

Now only deploys GitLab projects you have explicitly linked to from the GitLab control block in your account or team settings page, depending on where you linked your GitLab account. Without linking a project, no deployments will be made.

You can link projects across all the GitLab namespaces you have access to and unlink a project at any time.

You can also link a GitLab project from the New Project page:

Linking a GitLab project.

Sign Up or Login with GitLab

If you have, or will have, connected your personal GitLab account to your Now account, you can login with GitLab from our login page.

Alternatively; if you do not already have a Now account, you can sign up to ZEIT using your GitLab account from the sign up page.

Login to ZEIT with GitLab.

Usage

Once you link a GitLab project, we will deploy every git-push related to that project. If there is no now.json file within the project, we will deploy the project statically.

Using a now.json file, you can configure your projects to deploy as dynamic serverless functions.

Default Behavior

A Deployment for Each Push

Now for GitLab will deploy each push by default. This includes pushes to any branch and any merge requests made from those branches. This allows those working within the project to preview the changes made before they are pushed to production.

With every push, if Now is already building a previous commit, it will cancel that current build to start the most recent commit, ensuring you always have the latest changes deployed as quickly as possible.

Aliasing the Default Branch

If an alias is set within the now.json file, pushes and merges to the default branch (commonly "master") will be aliased automatically and made live to those defined aliases with the latest deployment made with a push.

For example, the following now.json configuration will make Now for GitLab alias the most recent push to my-zeit-website.com by default.

{
  "alias": ["my-zeit-website.com"]
}

If you decide to revert a commit that has already been aliased, the previous commit's deployment will automatically be aliased instantly; providing you with instant rollbacks.

Staging Aliases for Each Merge Request

The latest push to any merge request will automatically be aliased to a unique URL based on the project name, branch, and team or username. These URLs will be given through a comment on each merge request. For more on automatic aliases for git pushes and beyond in the Aliasing Documentation.

A staging alias created from a merge request.

Included Environment Variables

You may want to use different workflows and APIs based on the environment of the deployment based on Git information. To support that, Now will deploy your app with the following built-in environment variables when deploying with Now for GitLab:

Variable Key
Description
GITLAB_DEPLOYMENT
An indicator for whether the app was deployed by Now for GitLab.
GITLAB_PROJECT_NAMESPACE
The GitLab user, group, or sub-group that the project belongs to.
GITLAB_PROJECT_NAME
The name of the deployed project.
GITLAB_PROJECT_ID
The ID of the deployed project.
GITLAB_PROJECT_PATH
The GitLab project path.
GITLAB_COMMIT_REF
The branch that the app was deployed using.
GITLAB_COMMIT_SHA
The sha of the commit the app was deployed using.
GITLAB_COMMIT_MESSAGE
The message accompanying the commit that the app was deployed using.
GITLAB_COMMIT_AUTHOR_LOGIN
The username belonging to the author of the commit that the project was deployed using.
GITLAB_COMMIT_AUTHOR_NAME
The name belonging to the author of the commit that the project was deployed using.
Note: You can access these as build environment variables also.

Read Next

Learn more about deploying your apps with Now using the following resources: