> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/continuous-delivery/use-continuous-delivery/cd-building-blocks/environments/create-environment-groups.md).

# Create environment groups

Group environments so you can assign role permissions across multiple environments at once

{% hint style="info" %}
This feature is in Beta[^1] and requires enablement. [View all early access features.](/release-notes/features.md)

{% @harness-feature-flag-access/request-feature-flag-access module="continuous-delivery" pagePath="continuous-delivery/use-continuous-delivery/cd-building-blocks/environments/create-environment-groups" featureFlags="%5B%7B%22name%22%3A%22Cross%20scope%20environment%20groups%22%2C%22key%22%3A%22CDS\_CROSS\_SCOPED\_ENV\_GROUPS%22%2C%22status%22%3A%22BETA%22%2C%22description%22%3A%22Lets%20you%20add%20environments%20created%20at%20the%20Account%20and%20Organization%20levels%20to%20a%20project-level%20environment%20group.%22%7D%5D" %}
{% endhint %}

Environment groups let you group environments so you can assign permissions to multiple environments in a role. You can also use environment groups in multi-environment and infrastructure deployments.

## What you will learn from this topic

* How to [create an environment group](#create-an-environment-group) and add environments to it
* How to [add cross-scope environments](#create-a-cross-scope-environment-group) from the project, organization, and account levels
* How to [use environment groups](#use-environment-groups) in multi-environment deployments
* How to [reference environment group expressions](#reference-environment-groups) in a pipeline
* Understand the [limitations](#limitations) that apply when you plan environment group usage

## Before you begin

Before you begin, make sure you have the following:

* **Environments**: Create at least one environment before you build a group. Go to [Create environments](/continuous-delivery/use-continuous-delivery/cd-building-blocks/environments/create-environments.md) to create environments.
* **Permissions**: You need permission to view and manage environments at the scope where you create the group. Go to the [permissions reference](https://developer.harness.io/harness-platform/use-harness-platform/platform-access-control/permissions-reference) to review environment permissions.

***

## Create an environment group

Perform the following steps to create an environment group and add environments to it:

{% stepper %}
{% step %}

### Open environment groups

Go to **Project Settings** -> **Environments**, then select **Environment Groups** in the top-right corner of the page.
{% endstep %}

{% step %}

### Create the group

Select **New Environment Group**.
{% endstep %}

{% step %}

### Name the group and select environments

Enter a name for the environment group, and select the environments you want to add. You can also select **New Environment** to create a new environment and add it to this group.

{% hint style="info" %}
**Environment scope**

By default, you can only add environments in the same scope (Harness project, organization, or account) as the environment group. For example, if the environment group is configured at the project level, only project-level environments can be added.

With the cross-scope feature enabled, you can also add environments created at the account and organization levels. Go to [Create a cross-scope environment group](#create-a-cross-scope-environment-group) for details.
{% endhint %}

![Create environment groups dialog](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-a813832dad417a7690e6fac5ec2474919e2b29df%2Fservices-and-environments-overview-23.png?alt=media)

![Environment group with selected environments](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-4935ad3f807de56cdc9288aaf9394fe8174450ef%2Fenvironment-groups.png?alt=media)
{% endstep %}

{% step %}

### Submit the group <a href="#submit" id="submit"></a>

Click **Submit**.
{% endstep %}
{% endstepper %}

The following sample shows environment group YAML:

<details>

<summary>Sample environment group YAML</summary>

```yaml
environmentGroup:
  name: My Env Group
  identifier: My_Env_Group
  description: ""
  tags: {}
  orgIdentifier: default
  projectIdentifier: CD_Docs
  envIdentifiers:
    - myenv
    - dev_1679347042451
```

</details>

***

## Create a cross-scope environment group

With the cross-scope feature enabled, you can add environments from the project, organization, and account levels to one environment group. Perform the following steps to create a cross-scope environment group:

1. From your Project Settings, select **Environments**.
2. Select **Environment Groups** at the top-right corner of the page.
3. Click **New Environment Group**.
4. Enter a name for the environment group. Environments created at the **Project**, **Organization**, and **Account** levels appear under the respective tabs. Select the environments you need, then click **Submit**.

![Cross scope environment groups selection](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-3b7fd64148f3c7df7b5c9bd9787456f09a6242a2%2Fcross_scoped_env_groups.png?alt=media)

After the environment group is created, you can see all environments and their scopes listed.

![Cross scope environment groups list](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-3dca586153858fedbcd475c59049a3052f2c4cfa%2Fcross_scoped_env_groups-2.png?alt=media)

The following example shows YAML for a cross-scope environment group:

<details>

<summary>Cross-scope environment group YAML</summary>

```yaml
environmentGroup:
  name: demoEnvGroup
  identifier: demoEnvGroup
  description: ""
  tags: {}
  orgIdentifier: default
  projectIdentifier: CD_Docs
  envIdentifiers:
    - test
    - testenv1
    - org.testE
    - account.CDCNGAuto_EnvNg59wFkWCjQQ
    - account.CDCNGAuto_EnvNgdCz0sFChIM
```

</details>

Under `envIdentifiers`, the prefixes work as follows:

* Environments associated with the **Project** level have no prefix.
* Environments associated with the **Organization** level are prefixed with `org.`
* Environments associated with the **Account** level are prefixed with `account.`

***

## Use environment groups

Environment groups can only be used in multi-environment and infrastructure based deployments. By default, Harness loops through each environment in the environment group and deploys. You can specify whether you want to deploy to one environment or all the environments in the group.

***

## Reference environment groups

You can reference which environment group was selected by using expressions. Capture the values as output from the infrastructure step in the pipeline. The following expressions are available:

* Environment group name: `<+pipeline.stages.[STAGE_ID].spec.infrastructure.output.environment.envGroupName>`.
* Environment group ID: `<+pipeline.stages.[STAGE_ID].spec.infrastructure.output.environment.envGroupRef>`.

***

## Limitations

The following limitations apply when you work with environment groups:

* You cannot pass an environment group in Pipeline Studio as an expression.
* Open product questions for expression-based usage include:
  * How to handle infrastructures that have runtime input parameters when the expression is referenced
  * How to deploy to a subset of the environments in the environment group
  * How to propagate the environment group as an expression to the following stage

***

## Next steps

* [Create environments](/continuous-delivery/use-continuous-delivery/cd-building-blocks/environments/create-environments.md): Create the environments you add to a group.
* [Environment overview](/continuous-delivery/use-continuous-delivery/cd-building-blocks/environments/environment-overview.md): Review how environments and infrastructure definitions fit Continuous Delivery pipelines.
* [Service overrides](/continuous-delivery/use-continuous-delivery/cd-building-blocks/environments/service-overrides.md): Override service settings per environment after you group targets.

[^1]: Beta features are feature-complete but still being validated. Available on request.
