Configuration as Code (GitOps)

Everything you can do in the Harness platform GUI, you can do in YAML:

  • Using the Harness code editor, you can set up and manage accounts for artifact servers, cloud providers, and verification providers. You can edit application services, environments, workflows, etc, all in YAML.
  • You can sync your Git repo with Harness to simply use YAML files in your source repo to make changes to Harness.

Here is the same Harness workflow in the Harness GUI, Harness Code Editor, and a Git repo.

Other GitOps Topics:

Edit the Code in Harness

To view or edit the code for any account or application entity and its configuration, do the following:

  1. Click Setup.
  2. Click Configuration As Code. The code editor is displayed.

Edit any YAML file to make your changes and click Save.

Sync Scenarios Overview

The following tables provides an overview of the sync scenarios and how to configure them.

Sync Scenario

Configuration

Sync one-way (unidirectionally) from Harness to your Git repo.

Set up a SourceRepo Provider with your repo and do not enable the Generate Webhook URL option or apply the Webhook to the Git repo.

Select this SourceRepo Provider for all applications that you want to sync unidirectionally.

Sync two-way (bidirectionally) between Harness and your Git repo.

Set up a SourceRepo Provider with your repo and apply the Webhook created by the Generate Webhook URL option to the Git repo.

Select this SourceRepo Provider for all applications that you want to sync bidirectionally.

Stop synching an application with a Git repo, but keep the SourceRepo Provider connected for future syncs.

In the Git Sync setting for the application, turn off the Enable/Disable setting. Later, when you want to start syncing again, turn on the Enable/Disable setting.

Stop using a SourceRepo provider with an application.

In the Git Sync setting for the application, click DELINK.

Have the SourceRepo Provider sync bidirectionally with the Git repo, but have an application using that SourceRepo Provider only sync unidirectionally.

This is not available.

Harness Account-Level Sync

You can sync your Harness account with a Git repo. This can include all Harness account information and all applications, just the account information, or the account information and one or more applications.

If you sync the Harness account information and all applications, you can sync one or more applications with other repos or branches in the future.

Before Harness syncs with your Git repo it will confirm that all Harness' settings are in a valid state. If a connection is not working, such as a connection to an Artifact Server or Cloud Provider, Harness will not sync with your Git repo.

To sync a Harness account with Git, do the following:

  1. Add your Git repo as a SourceRepo Provider in Harness. For more information, see Add SourceRepo Providers.
  2. Click Setup.
  3. Click Configuration As Code. The Configuration As Code page appears.
  4. Click the ellipsis next to the Search field, and then click Setup Git Sync.





    The Git Sync dialog appears.
  5. In Git Connector, select a Harness SourceRepo Provider. For information on setting up a SourceRepro Provider, see Add SourceRepo Providers.
  6. In Branch Name, enter the name of the repo branch to sync with the Harness account. This might be the master branch, or another branch where you want to keep the Harness account-level settings.
  7. To enable sync between Harness and the repo in the SourceRepo provider, ensure Enable Git Sync is enabled. For more information, see Add SourceRepo Providers.

Your Harness account is now synced with your Git repo. Open your Git repo to see the Harness account. Here is an example using GitHub:

Two-Way Git Sync

When you select the Enable Git Sync option and apply the generated Webhook to your repo (as described in Add SourceRepo Providers), any changes you make in your repo are pushed to Harness.

Below is an example of a CD pipeline.yaml file within the folder harness/Setup/Applications/RetailApplication/Pipelines

The file contains a pipeline with four deployment stages: Dev, QA, Approval, and Prod.

When you commit the YAML file it to the branch, seconds later Harness is fully synced, and the new pipeline is available to view in the UI:

If you’d like to view or make edits to the pipeline YAML, you can click the config-as-code icon:

This allows you to view/edit the YAML in the context of the pipeline like this: 

The same config-as-code can be done for creating new services, environments, workflows, triggers, and everything else in the Harness platform.

Harness Application-Level Sync

Whether or not you sync your Harness account with your Git repo, you can sync any Harness application with your repo by itself.

To sync a Harness application with a Git repo, do the following:

  1. Add your Git repo as a SourceRepo Provider in Harness. For more information, see Add SourceRepo Providers.
  2. Click Setup.
  3. Click Configuration As Code. The Configuration As Code page appears.
  4. Hover your cursor over the name of the application you want to sync. A Git Sync icon appears.
  5. Click the Git Sync icon. The Git Sync dialog appears.
  6. In Git Connector, select a Harness SourceRepo Provider. For information on setting up a SourceRepro Provider, see Add SourceRepo Providers.
  7. In Branch Name, enter the name of the repo branch to sync with the Harness application.
  8. To enable sync between Harness and the repo in the SourceRepo provider, ensure Enable Git Sync is enabled. For more information, see Add SourceRepo Providers.
  9. Click SUBMIT. The Git Sync icon is next to the application.

To refresh a sync, click the Refresh icon.

Look in your Git repo, and you will see the Harness application added.

You can remove the Git sync connection between a Harness account and/or application by delinking the connection.

To delink a Git connection, do the following:

  1. Click Setup.
  2. Click Configuration As Code. The Configuration As Code page appears.
  3. Select the Git Sync connection you want to delink.
    1. For an account-level connection, click the ellipsis next to the search field, and then click Setup Git Sync.
    2. For an application-level connection, hover over the application's Git Sync icon, and then click the icon.
  4. In the Git Sync dialog, click DELINK.
  5. Click CONFIRM to confirm the removal of the Git sync.

Rapid Development with Harness GitOps

One of the advantages with Harness GitOps is the ability to clone or duplicate a Harness application entity quickly in the Git repo, and then have the cloned entity show up in the Harness platform.

For example, you can clone a Harness environment in the Harness GUI using the Clone button.

But if you wish to make several copies, this can be time-consuming in the GUI.

With Harness GitOps, you can simply duplicate the environment folder in Git, give the duplicate folder a unique name, and push it to the origin. The new environment will appear in Harness.


How did we do?