Currently, Bi-Directional sync is behind the feature flag
PIE_GIT_BI_DIRECTIONAL_SYNC. Contact Harness Support to enable the feature.
By default, Harness Git Experience syncs unidirectionally, from Harness to your Git repos. Enable this setting to have Git Experience sync two-way (bidirectionally) between Harness and your Git repo.
Changes made on either the Git repo or Harness are synched automatically.
This topic explains how to set up and use bidirectional sync.
Please review the following important notes:
- Phase 1 of the bi-directional sync feature applies to Harness pipelines, templates, and input sets. Phase 2 of this feature will include Harness services and environments.
- If users make changes on the Harness and Git side at the same time, precedence is given on a first come, first served basis.
- Customers using the current unidirectional sync (Harness --> Git) functionality can migrate to bi-directional sync using the steps in this topic. The process involves enabling an account-level setting.
- If you make an invalid YAML change to the YAML in the Git repo file, Harness will not accept the invalid YAML during sync. An Invalid YAML Detected error appears. You can fix the invalid YAML in Harness and save the entity.
- If your Git repo server is on-premise, it must have connectivity to Harness SaaS.
Configure bi-directional sync
To set up bi-directional sync, do the following:
In your Harness account, go to Account Settings, select Account Resources, and then select Default Settings.
Expand Git Experience, and then enable the Enable Bi-Directional Sync setting.
Create the webhook
When you create the webhook in Harness, it is automatically registered in your repo. For webhook registration, ensure that the Harness Git connector you use in the steps below has the necessary credentials. For example, for GitHub, ensure that you use a GitHub user account that is a repo admin and that the Personal Access Token includes all repo, user, and
admin:repo_hook options for scopes.
You will need a webhook to your repo to use bi-directional sync:
In Harness, go back to Account Resources. You will see a new option named Webhooks.
Select Webhooks, and then select New Webhook.
In Git Connector, select or create a Harness Git Connector for your repo.
In Repository, select the repo where you are going to store the Harness entities, such as pipelines.
In Folder Path, enter the path to the location in the repo that stores your Harness entities. Typically, the path starts with
.harnessand is followed by subfolders.
The Folder Path setting is optional. If you omit a folder path, Harness will sync everything in the repo.
Select Add. The webhook is added. You can navigate to your repo webhook settings to see the new webhook.
In the Webhooks page, you can see the Events tab. Once you have synched an entity with the Git repo, the Git events are displayed here. You can view Git event Ids for troubleshooting.
Sync a Harness entity
For this example, we'll create a new remote pipeline, sync it with the repo, make a change on the Git side, and then see the change on the Harness side.
- In Harness, in Pipelines, select Create a Pipeline.
- In How do you want to setup your pipeline?, select Remote.
- Specify the Git Connector, Repository, and Git branch for storing and syncing the pipeline.
- In YAML Path, you can enter the path to a repo folder where, if needed.
- Select Start. The pipeline is created.
- Add a CD or Custom stage to the pipeline and save it.
- In your repo, confirm that the YAML file for the pipeline exists.
- In your repo, open the YAML file for the pipeline and commit a change. For example, add a
- Back in Harness, review the pipeline to see the changes.
Harness provides the following troubleshooting features to help you diagnose sync errors:
Webhooks page: In Account Settings, Account Resources, Webhooks, you can select the webhook for your Harness entity sync and view each event on the Events tab. For each event, you can select Payload Details to see the payload.
View Webhook Events: in the Git information on your Harness entity, you can select View Webhook Events and see each event and payload for that entity.