> ## Documentation Index
> Fetch the complete documentation index at: https://docs.testdino.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Playwright Environment Mapping

> Map Git branches to environments for targeted test reporting.

export const VideoSchema = ({name, description, thumbnailUrl, uploadDate, duration, contentUrl, embedUrl}) => {
  const schema = {
    "@context": "https://schema.org",
    "@type": "VideoObject",
    name,
    description,
    thumbnailUrl,
    uploadDate,
    ...duration ? {
      duration
    } : {},
    ...contentUrl ? {
      contentUrl
    } : {},
    ...embedUrl ? {
      embedUrl
    } : {},
    publisher: {
      "@type": "Organization",
      name: "TestDino",
      logo: {
        "@type": "ImageObject",
        url: "https://docs.testdino.com/logo/light.svg"
      }
    }
  };
  return <script type="application/ld+json" dangerouslySetInnerHTML={{
    __html: JSON.stringify(schema)
  }} />;
};

<VideoSchema name="Environment Mapping in TestDino" description="How to map Git branches to environments for targeted Playwright test reporting in TestDino." thumbnailUrl="https://i.ytimg.com/vi/oVaYPIsYrJA/maxresdefault.jpg" uploadDate="2025-12-16T00:00:00+00:00" contentUrl="https://www.youtube.com/watch?v=oVaYPIsYrJA" embedUrl="https://www.youtube.com/embed/oVaYPIsYrJA" />

<Callout icon="book-open" color="#3B82F6">
  **What you'll learn**

  * How to map branches to environments using exact match or patterns
  * How test results route to the correct environment automatically
  * How environment mapping affects dashboards, filters, and alerts
</Callout>

Branch patterns map your Git branches to environments (Dev, Staging, Production). Test results automatically route to the correct environment based on the branch that triggered the run.

<iframe className="w-full rounded-lg h-[500px]" src="https://www.youtube.com/embed/oVaYPIsYrJA" title="Environment Mapping video" frameBorder="0" allow="accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; embedding" referrerPolicy="strict-origin-when-cross-origin" allowFullScreen />

## Quick Reference

| Symbol | Meaning          | Example                           |
| :----- | :--------------- | :-------------------------------- |
| `^`    | Start of name    | `^dev` → `dev/test` ✓             |
| `$`    | End of name      | `main$` → `main` ✓                |
| `(?i)` | Case-insensitive | `(?i)^main$` → `MAIN` ✓           |
| `\d`   | Any digit        | `v\d` → `v1` ✓                    |
| `\|`   | OR               | `dev\|qa` → `dev` or `qa` ✓       |
| `( )`  | Group            | `^(dev\|qa)/` → `dev/` or `qa/` ✓ |

See [full symbol reference](#regex-symbols-reference) below.

## Pattern Types

### Exact Match

Match the branch name exactly as written.

| Pattern | Matches | Does not match                |
| :------ | :------ | :---------------------------- |
| `main`  | `main`  | `main-backup`, `feature/main` |

Use exact match for specific branch names like `main`, `master`, `production`.

### Regex Patterns

Use regular expressions for flexible matching.

| Pattern            | Description               | Matches                          |
| :----------------- | :------------------------ | :------------------------------- |
| `^dev/`            | Starts with `dev/`        | `dev/feature-123`, `dev/bug-fix` |
| `^main$`           | Exactly `main`            | `main`                           |
| `^(main\|master)$` | Either `main` or `master` | `main`, `master`                 |
| `^release/v\d+`    | Release with version      | `release/v1`, `release/v2.0`     |

## Common Patterns

### Branch Prefixes

| Pattern     | Description        | Matches                            |
| :---------- | :----------------- | :--------------------------------- |
| `^feature/` | Feature branches   | `feature/login`, `feature/payment` |
| `^hotfix/`  | Hotfix branches    | `hotfix/critical-bug`              |
| `^release/` | Release branches   | `release/v1.0`, `release/2024-01`  |
| `^pull/\d+` | GitHub PR branches | `pull/123/merge`, `pull/456/head`  |

### Version Numbers

| Pattern                    | Description             | Matches                      |
| :------------------------- | :---------------------- | :--------------------------- |
| `^release/v\d+`            | Version with `v` prefix | `release/v1`, `release/v2.0` |
| `^release/\d+\.\d+`        | Semantic version        | `release/1.0`, `release/2.5` |
| `^release/v\d+\.\d+\.\d+$` | Exact semver            | `release/v1.0.0`             |

### Case-Insensitive

Use `(?i)` when your team uses inconsistent casing:

| Pattern         | Matches                            |
| :-------------- | :--------------------------------- |
| `(?i)^main$`    | `main`, `MAIN`, `Main`             |
| `(?i)^release/` | `release/`, `RELEASE/`, `Release/` |

## Common Use Cases

### Git Flow

| Environment | Pattern              |
| :---------- | :------------------- |
| Production  | `^(main\|master)$`   |
| Staging     | `^(staging\|stage)$` |
| Development | `^(dev\|develop)$`   |
| Features    | `^feature/`          |
| Hotfixes    | `^hotfix/`           |
| Releases    | `^release/`          |

### Environment Prefixes

| Environment | Pattern  |
| :---------- | :------- |
| Production  | `^prod/` |
| Staging     | `^stg/`  |
| QA          | `^qa/`   |
| Development | `^dev/`  |

### Version Releases

| Environment        | Pattern                          |
| :----------------- | :------------------------------- |
| Production         | `^release/v\d+\.\d+\.\d+$`       |
| Release Candidates | `^release/v\d+\.\d+\.\d+-rc\d+$` |
| Beta               | `^release/v\d+\.\d+\.\d+-beta$`  |

## Regex Symbols Reference

| Symbol | Meaning                   | Example       | Matches                     |
| :----- | :------------------------ | :------------ | :-------------------------- |
| `^`    | Start of branch name      | `^dev`        | `dev/feature` ✓, `my-dev` ✗ |
| `$`    | End of branch name        | `main$`       | `main` ✓, `main-old` ✗      |
| `(?i)` | Case-insensitive          | `(?i)^main$`  | `main`, `MAIN` ✓            |
| `.`    | Any single character      | `dev.`        | `dev/`, `dev-`, `dev1`      |
| `*`    | Zero or more of previous  | `dev.*`       | `dev`, `dev/feature`        |
| `+`    | One or more of previous   | `dev.+`       | `dev/feature` ✓, `dev` ✗    |
| `\d`   | Any digit (0-9)           | `v\d`         | `v1`, `v2`, `v9`            |
| `\|`   | OR                        | `dev\|qa`     | `dev`, `qa`                 |
| `[ ]`  | Any character in brackets | `[0-9]`       | `0`, `1`, `2`, ... `9`      |
| `( )`  | Group patterns            | `^(dev\|qa)/` | `dev/test`, `qa/test`       |
| `[^ ]` | NOT in brackets           | `[^0-9]`      | `a`, `b`, `-` (not digits)  |

## Best Practices

### Do

| Practice            | Good                                      | Bad                          |
| :------------------ | :---------------------------------------- | :--------------------------- |
| Anchor at start     | `^dev/`                                   | `dev/` (matches anywhere)    |
| Use `$` for exact   | `^main$`                                  | `^main` (matches `main-old`) |
| Test patterns first | Use [regex101.com](https://regex101.com/) | Deploy untested              |
| Use `(?i)` for case | `(?i)^release/`                           | `^[Rr][Ee][Ll]...`           |

### Avoid

| Pattern    | Problem                            |
| :--------- | :--------------------------------- |
| `.*`       | Matches everything                 |
| `.+`       | Matches any branch                 |
| `dev*`     | Matches `d`, `de`, `dev`           |
| `dev;echo` | Security risk (special characters) |

## Validation

### Errors (blocks saving)

* Invalid characters: `;`, `&`, `` ` ``, `"`, `'`, `<`, `>`, `%`
* Invalid regex syntax: unclosed brackets, invalid escapes

### Warnings (allows saving)

* Unanchored patterns that might match unintentionally
* Suggestion provided to fix

## Testing Patterns

### Example: `^dev/`

| Branch              | Match | Reason                     |
| :------------------ | :---- | :------------------------- |
| `dev/feature-login` | ✓     | Starts with `dev/`         |
| `dev/bug-fix`       | ✓     | Starts with `dev/`         |
| `development/test`  | ✗     | Starts with `development/` |
| `my-dev/branch`     | ✗     | Does not start with `dev/` |

### Example: `^release/v\d+\.\d+`

| Branch               | Match | Reason                     |
| :------------------- | :---- | :------------------------- |
| `release/v1.0`       | ✓     | Matches pattern            |
| `release/v2.5.3`     | ✓     | Matches pattern (and more) |
| `release/version1.0` | ✗     | Missing `v` before number  |
| `release/beta`       | ✗     | No version number          |

## CLI Override

<iframe className="w-full rounded-lg h-[500px]" src="https://www.youtube.com/embed/2jUSi6EZEqw" title="CLI Environment Override video" frameBorder="0" allow="accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerPolicy="strict-origin-when-cross-origin" allowFullScreen />

Bypass branch mapping with the `--environment` flag:

```bash theme={null}
npx tdpw upload ./playwright-report --token="..." --environment="staging"
```

The CLI flag takes priority over branch mapping rules. See [CLI reference](/cli/testdino-playwright-nodejs) for details.

## Related

GitHub Actions, status checks, and CI optimization.

<CardGroup cols={2}>
  <Card title="Project Settings" icon="gear" href="/platform/project-settings">
    Configure branch mapping
  </Card>

  <Card title="GitHub Actions" icon="github" href="/guides/playwright-github-actions">
    CI workflow setup
  </Card>

  <Card title="Node.js CLI" icon="node-js" href="/cli/testdino-playwright-nodejs">
    Upload options reference
  </Card>

  <Card title="Analytics by Environment" icon="chart-line" href="/platform/analytics/environment">
    View results per environment
  </Card>
</CardGroup>
