PR Pipelines Basics
This topic shows you how to create a Harness PR pipeline in Harness GitOps to make changes to one of an ApplicationSet's target environments.
Often, even though your ApplicationSet syncs one microservice/application to multiple target environments, you might want to change a microservice in just one of the target environments, such as a dev environment. A Harness PR Pipeline enables you to do this.
This topic builds on the ApplicationSet created in Harness GitOps ApplicationSets. Ensure you have read that topic and, ideally, have set up an ApplicationSet in Harness before creating a PR pipeline.
It is also recommended that you go through the basics of Harness PR pipelines before proceeding further.
Check out this example using ApplicationSet with PR Pipelines to get started with ApplicationSet with Harness GitOps PR Pipelines.
When you deploy a Harness PR pipeline, you indicate the target environment application and the config.json keys/values you want changed. Harness creates the pull request in your Git repo and merges it for you. Once complete, the target environment application has the new keys/values.

Prerequisites
Before creating a PR pipeline, ensure you have:
-
Harness Environments: Create environments (e.g.,
dev,prod) that match your Git repository folder structure. See Create GitOps Environments for detailed instructions. -
Environment Variables (Optional): Configure environment variables for the key-value pairs you want to update in your configuration files. See Configure Environment Variables.
-
GitOps Clusters Linked to Environments: Associate your GitOps clusters with the appropriate environments. See Add GitOps Clusters.
-
Harness Service: Create a service with Release Repo and Deployment Repo manifests configured. See Create a GitOps Service.
Name your Harness environments to match your Git directory structure. For example, if your Git paths are:
cluster-config/engineering/dev/config.jsoncluster-config/engineering/prod/config.json
Create environments named dev and prod. This allows the <+env.name> expression in your service manifest paths to resolve correctly at runtime.

Before proceeding, ensure you have created a GitOps service with the following manifests configured:
-
Release Repo Manifest: Points to your
config.jsonfiles using the<+env.name>expression- Example path:
cluster-config/engineering/<+env.name>/config.json
- Example path:
-
Deployment Repo Manifest: Points to your ApplicationSet template
- Example path:
git-generator-files.yaml
- Example path:
For detailed instructions on creating and configuring a GitOps service, see Create a GitOps Service.
For information on using cluster-specific paths with <+cluster.name> expressions, see Service Variables.
Create the PR pipeline
Finally, create the Harness PR pipeline by following these steps-
-
In your Harness project, click Pipelines.
-
Click Create a Pipeline.
-
In Create new Pipeline, enter the name PR Pipeline, and then click Start.
-
Click Add Stage, and select Deploy.

-
Enter the following and click Set Up Stage:
- Stage Name: enter PR Example.
- Deployment Type: select Kubernetes.
- Enable the GitOps option.

The stage is created and the service settings appear.
-
Please select the service that you have already configured.

-
For the stage environment, we'll use a Harness runtime input. When you run the pipeline, Harness will prompt you for a value for the environment. You can select the environment you want to use for the PR.
You can also use Expressions here. The value provided for the environment expression will propagate through all the PR steps. Note: only expressions that resolves to strings are valid and considered during execution.
-
Set Specify environment or environment group as a runtime input.

-
Click Continue.
-
Review execution steps
In Execution, Harness automatically adds a few common PR pipeline steps. These steps and other PR pipeline steps, are briefly described below.
Harness automatically adds the Update Release Repo, Merge PR and Fetch Linked Apps Steps, which are ready to be run without any configuration. However, to further customize these steps or add other optional steps, please refer to Harness GitOps pipeline steps.
Update Release Repo step
This step fetches your JSON files, updates them with your changes, performs a commit and push, and then creates a PR.
You can also enter variables in this step to update key-value pairs in the config file you are deploying.
If there is a matching variable name in the variables of the Harness service or environment used in this pipeline, the variable entered in this step will override them.
For more information, please refer to Update Release Repo step.

Merge PR step
This step simply merges the new PR.
Fetch Linked Apps step
The Fetch Linked Apps step provides app information, such as the app name, agent identifier, and URL to the Harness GitOps app.
Configuring the Deployment Repo manifest in your service is required for this step to execute correctly.
This information is displayed on the Output tab of the step.

You can copy the expression for any output in the Output Name column and use it to reference the output value in a subsequent Shell Script step or step setting.
Revert PR
This step reverts the commit passed and creates a new PR. Use this step if you want to run any tests or automation on the pipeline and then revert the commit done by the Update Release Repo step.
The Revert PR step uses the commitId of the Update Release Repo step as input. The commitId can be an expression, runtime input, or a static value. For example, <+pipeline.stages.deploy.spec.execution.steps.updateReleaseRepo.updateReleaseRepoOutcome.commitId>.
The Revert PR step creates a new branch and creates a commit to revert the changes done in the Update Release Repo step commit.
You can create another Merge PR step to merge the Revert PR step.
You can create a maximum of two Merge PR steps in a stage.
Run and verify the PR pipeline
Now your PR pipeline is ready.
-
Click Save, and then click Run.
-
In Run Pipeline, in Specify Environment, select the dev Environment.
-
In Environment Variables, for asset_id, enter the value
12345678. -
In Specify GitOps Clusters, select the engineeringdev cluster.

-
Click Run Pipeline.
You can review the deployment steps in real-time.

Here's an example of each step:
- Service:
Starting service step...
Processing service variables...
Applying environment variables and service overrides
Processed service variables
Processed artifacts and manifests
Completed service step
- GitOps Clusters:
Environment(s): {dev}
Processing clusters at scope PROJECT
Following 1 cluster(s) are present in Harness Gitops
Identifiers: {engineeringdev}
Following 1 cluster(s) are selected after filtering
Identifiers: {engineeringdev}
Completed
- Update Release Repo:

- Merge PR:
PR Link: https://github.com/wings-software/gitops-pipeline-demo/pull/155
Pull Request successfully merged
Commit Sha is bcd4f2f73a47b74dba54habbcd10a6679ed99a
Done.
- Revert PR:
Setting git configs
Using optimized file fetch
Created revert PR https://github.com/wings-software/gitops-pipeline-demo/pull/156
Done.
- Merge PR_1:
PR Link: https://github.com/wings-software/gitops-pipeline-demo/pull/156
Pull Request successfully merged
Commit Sha is da3c393560bf5e831a7b4fa123456c1eafb989ac
Done.
- Check the repo to see that the
config.jsonfile for the dev environment has been updated with the new asset_id value:

Congratulations! Your PR Pipeline was successful.