Environments
Learn how to create and manage GitOps environments in Harness.
This topic describes how to create and manage Harness GitOps environments. Environments represent your deployment targets and are used in ApplicationSets and PR pipelines to organize and track your GitOps deployments.
What is a GitOps Environment?
A GitOps environment in Harness represents a deployment target (such as dev, staging, or production) and is associated with one or more GitOps clusters. Environments help you:
Organize deployments by lifecycle stage (development, staging, production)
Associate clusters with specific deployment targets
Track application deployments across different environments
Enable environment-specific configurations in PR pipelines
Prerequisites
Before creating a GitOps environment, ensure you have:
At least one GitOps cluster configured
Appropriate RBAC permissions to create environments
Create a GitOps Environment
Follow these steps to create a GitOps environment:
Step 1: Navigate to Environments
In your Harness project, go to Deployments > Environments.
Click + New Environment.
Step 2: Configure Environment Details
Name: Enter a unique name for your environment (e.g.,
dev,staging,prod).Environment Type: Select the deployment type:
Production: For production environments
Pre-Production: For development, staging, or testing environments
Click Save.

The environment is now created.
Step 3: Add GitOps Clusters
In the environment details page, navigate to the GitOps Clusters tab.

Click + Cluster to add a cluster to this environment.
In the cluster selection dialog, you'll see all available clusters based on:
Project level: Clusters created in the current project
Organization level: Clusters shared at the organization level
Account level: Clusters shared at the account level

Select the cluster(s) you want to associate with this environment.
Click Save.
Your GitOps environment is now ready to use!

Configure Environment Variables
Environment variables allow you to define configuration values that can be used in PR pipelines to update application configuration files dynamically.
Create Environment Variables
In the environment details page, navigate to the Configuration tab.
Under Advanced, click Variables > New Variable Override.
Enter the following details:
Name: Enter the variable name (e.g.,
asset_id,image_tag,replicas)Type: Select the variable type (String, Number, Secret)
Value: Enter a default value or select Runtime Input to provide the value during pipeline execution
Click Save.
Variable Override Priority
When using environment variables in PR pipelines:
Values specified in the Update Release Repo step have the highest priority
Environment variables override service variables
Service variables have the lowest priority
By default, the Update Release Repo step writes service and environment variables into the Release Repository file. To insert only the variables defined in the step, enable Don't Propagate Pipeline Variables. Go to Update Release Repo to configure this option.
For more information on override priority, go to Service Overrides.
Using GitOps Environments
In ApplicationSets
When creating an ApplicationSet, you select an environment in the Overview step. This automatically adds the harness.io/envRef label to your ApplicationSet, enabling:
Environment-based tracking and filtering
RBAC policies based on environments
Integration with PR pipelines
In PR Pipelines
Environments play a crucial role in PR pipelines by enabling environment-specific configuration updates. When you configure a service with dynamic paths using the <+env.name> expression, Harness resolves this to the selected environment name at runtime.
Environment Name Resolution
For example, if your Git repository structure looks like this:
And your service manifest path is configured as:
When you run a PR pipeline and select the dev environment, Harness resolves the path to:
This allows you to update configuration files for specific environments without creating separate services or pipelines for each environment.
Manage GitOps Environments
View Environment Details
Go to Deployments > Environments.
Click on an environment to view its details.
The GitOps Clusters tab shows all clusters associated with this environment.
Add or Remove Clusters
Navigate to the environment details page.
Go to the GitOps Clusters tab.
To add a cluster, click + Cluster and select from available clusters.
To remove a cluster, click the delete icon next to the cluster name.
Delete Environment
Go to Deployments > Environments.
Find the environment you want to delete.
Click the three vertical dots (⋮) next to the environment.
Select Delete.
Confirm the deletion.
Deleting an environment does not delete the associated clusters or applications. However, ApplicationSets and pipelines referencing this environment may be affected.
Best Practices
Use descriptive names: Name environments clearly (e.g.,
dev,staging,prod) to avoid confusionMatch environment names with Git paths: If using dynamic paths in services, ensure environment names match your Git repository structure
Organize by lifecycle: Use Pre-Production for dev/staging and Production for prod environments
Associate appropriate clusters: Only add clusters that are meant for that specific environment
Consistent naming: Use the same environment naming convention across projects for easier management
Next Steps
Last updated
Was this helpful?