- Expose staging or preview builds on-demand with secure, authenticated URLs.
- Use dynamic endpoint URLs based on branch names, PR numbers, or commit SHAs.
- Apply Traffic Policy to add authentication, logging, and access control to every preview.
- Clean up automatically when CI jobs finish.
What you’ll need
- A CI/CD platform like GitHub Actions, GitLab CI, or Jenkins
- A pay-as-you-go account for custom domains
1. Reserve a wildcard domain
Navigate to the Domains section of the ngrok dashboard and click New + to reserve a custom wildcard domain like*.preview.example.com.
You’ll then need to set up CNAME records with your DNS provider.
This wildcard lets you dynamically create preview URLs like pr-123.preview.example.com for each pull request or branch.
2. Create a Cloud Endpoint
Navigate to the Endpoints section of the ngrok dashboard, then click New + and Cloud Endpoint. In the URL field, enter the domain you just reserved to finish creating your Cloud Endpoint.3. Add routing with Traffic Policy
While viewing your new Cloud Endpoint in the dashboard, copy the policy below and paste it into the Traffic Policy editor.pr-123.preview.example.com get forwarded to https://pr-123.internal, which connects to the ephemeral container or service running your deploy preview.
4. Add authentication to your previews
Deploy previews shouldn’t be publicly accessible. Use the OAuth action to require reviewers to authenticate before accessing any preview and deny all requests from those without aexample.com email:
5. Start an Agent Endpoint from your CI pipeline
In your CI/CD workflow, start an internal Agent Endpoint that matches the preview URL pattern. The exact setup depends on your CI platform, but here’s a GitHub Actions example:https://pr-{PR_NUMBER}.internal.
The Cloud Endpoint you configured earlier routes traffic from pr-{PR_NUMBER}.preview.example.com to this internal endpoint.
When the job finishes, the agent stops and the preview disappears.
6. Try out your endpoint
Visit the domain you reserved either in the browser or in the terminal using a tool likecurl.
You should see the app or service at the port connected to your internal Agent Endpoint.
7. Route external testing tools (optional)
If you use external testing services like BrowserStack, Sauce Labs, or a third-party QA platform, they can hit your preview URLs directly. Add IP restrictions to allow only your testing provider:What’s next?
- View your preview traffic in Traffic Inspector to debug failing tests or observe how reviewers interact with previews.
- Explore other CI/CD patterns like blue-green deployments or canary deployments for production rollouts.
- Use the Kubernetes Operator to manage ephemeral workloads in Kubernetes clusters with the same patterns.