Create Harness GitOps PR pipelines
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.
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.
For the PR Pipeline, we'll create two Harness environments, dev and prod. These names are the same as the folder names in the repo:
We use the same names so that when we select a Harness environment we can pass along the same name as the target folder. The path to your two config.json
files would be the following-
examples/git-generator-files-discovery/cluster-config/engineering/dev/config.json
examples/git-generator-files-discovery/cluster-config/engineering/prod/config.json
Now, let's create Harness environments for each of the target environments - dev and prod.
Create Harness environments for each target environment
An environment logically corresponds to your dev
, staging
, or production
environments. Ideally, your ApplicationSet configuration files would differ on the basis of the environments they would deploy to.
To create a dev
environment, do the following:
- In your Harness project, select Environments.
- Select New Environment.
- Do the following, and then select Save:
- Name Enter
dev
. - Environment Type: Select Pre-Production.
- Name Enter
The new environment is created. Similarly, create another environment prod
and select Environment Type as Production.
Create a variable for JSON key-value pair to be updated
Next, we'll add a variable for the JSON key-value we will be updating.
-
In Advanced, in Variables, click New Variable Override.
-
In the variable Name, enter asset_id and click Save.
The
asset_id
name is a key-value in theconfig.json
files for both dev and prod: -
For variable Value, select Runtime Input:
Later, when you run the pipeline, you'll provide a new value for this variable, and that value will be used to update the
config.json
file.
Repeat this process for the prod
environment.
Linking GitOps clusters to the Harness environments
Before updating your application's config.json
values, Harness also resolves the GitOps clusters in which your application is deployed. The referenced cluster is the same cluster you created when you deployed your application. You do not need to create any new entities in Harness.
Once you link GitOps clusters to an environment, whenever you select an environment in a pipeline, you can select the environment's linked GitOps clusters. This ensures that you can control where applications are to be updated even within the same environment.
Next, you need to link your GitOps clusters to your Harness environment.
Link the engineering-dev GitOps cluster to the dev
environment and engineering-prod GitOps cluster to the prod
environment.
To link the Harness GitOps clusters with the dev
environment, do the following:
- Click GitOps Clusters.
- Click Select Cluster(s).
- Select engineering-dev.
- Click Add.
The Harness GitOps cluster is now linked to the environment.
Similarly, link the engineering-prod GitOps cluster to the prod
environment.
You can link multiple clusters to a single environment.