Preview, or ephemeral, environments have become an essential part of CI/CD workflows. Software developers typically deploy code changes to such short-lived environments so that the team can perform automated end-to-end testing and manual validation to ensure everything functions and looks as expected early on in the deployment cycle.
Illustration of a CI/CD pipeline with a preview (ephemeral) environment stage
Depending on your CI/CD workflow, there are two different ways you can set up your mabl environments to run tests against short-lived preview environments:
Before you start
This article assumes you have a working CI/CD pipeline and are familiar with using the mabl CLI to trigger deployment events.
One mabl environment with URL overrides
The most common approach is to create a single preview environment in mabl and use a dynamic URL override to run tests against the preview environment. For example, use the mabl CLI to create a deployment event and include the --app-url
option to override the environment's base URL with a preview URL:
mabl deployments create -e {preview-environment-id} --app-url {url-override}
The URL override approach assumes that you use the same environment variables for each mabl deployment event and that you don't need to set up a separate secure tunnel with mabl Link for each deployment
Most customers with private preview environments will set up a mabl Link Agent on a virtual machine that has network access to all internal preview environments. That way you don't have to install a new Link Agent and wait up to five minutes to establish a secure tunnel for each deployment.
Separate mabl environments for each preview deployment
If each preview environment requires a separate secure Link tunnel or different environment variables, you can create separate mabl environments, provision each environment as needed, and delete those environments from mabl when you're finished.
Before implementing this workflow, an owner in your workspace needs to generate two mabl API keys:
- "Link Agent" API key - to start up the Link Agent
- "Command Line Interface" API key - to authenticate the mabl CLI
Start up the Link Agent and install the mabl CLI in your CI/CD tool. Then use the mabl CLI to create a preview environment and associate it with an application, URL, Link Agent name, and variables:
mabl auth activate-key {cli-api-key} mabl environments create --name {environment_name} --workspace-id {mabl_workspace_id} \ --application-id {app_id} --app-url {web_url} \ --link {agent_name} --variables {var1:value1, var2:value2}
When you create the environment, the mabl CLI returns an environment ID. Store this ID in a variable so that you can use it in subsequent steps.
After creating the preview environment, you can configure your CI/CD tool to run mabl tests as a deployment event. See the article on triggering deployment events in the mabl CLI for a full list of options.
mabl deployments create -e {environment_id}
If you need to associate the newly created preview environment with multiple application URLs, run the following CLI command as often as needed:
mabl environments urls add {environment_id} --application-id {app_id} \ --app-url {web_url} --api-url {api_url}
The last step is to tear down the preview environment. To keep your workspace clean and free up tunneling infrastructure resources for new preview environments, delete both the environment and the Link Agent
mabl environments delete {environment_id} mabl link-agents delete {agent_name}
When you delete the environment, you delete all of its associated URLs and variables.