Add Source Repo Providers

Updated 1 week ago by Michael Cretzman

You can add one or more Git repositories (Github, Bitbucket, GitLab, etc) as Source Repo Providers in Harness. Once added, a Git repo can be used to sync your Harness account and applications with your repo. Next, any changes you make in your repo or in Harness are automatically synched.

You can use multiple repositories. You can sync the Harness account-level to one repo or branch, and sync each Harness application with its own repo or branch.

For information about using Git repos to perform GitOps with Harness, see Configuration as Code (GitOps). For information on triggering Harness workflows and pipelines using Git Webhooks, see Add a Trigger.

Harness Sync Options

Here are the options for syncing Harness with your repos:

  • One Harness application can be on one repo/branch.
  • Multiple Harness applications can be on one repo, all in one branch, or each application in its own branch.
  • A Harness application cannot be in multiple repos.
  • When you create a new Harness application, you can choose to sync it with a repo.
  • If you create a new Harness application in a synched repo (by adding the required files and folders), Harness will sync and add the new Harness application.
  • If you move a synched Harness application from one repo to a new repo, Harness will accept changes from new repo only.
  • Admins that want access to all synched Harness applications in the repo must have an admin account in the Git repo that contains all the applications.
For information about synching scenarios, see Sync Scenarios Overview.

Add a Source Repo Provider

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 add a source repo, do the following:

  1. Click Setup.
  2. Click Connectors.
  3. Click Source Repo Providers, and then click Add Source Repo Provider. The Git Connector dialog appears.
  4. Fill out the Git Connector dialog and click SUBMIT. The Git Connector dialog has the following fields.

Field

Description

Name

Enter a name for the repo connection. This is the name you will select when you sync your Harness account and applications in Configuration as Code.

You could create a Source Repo Provider for the Harness admin account, such as Admin_GitLab. Later, you can create a Source Repo account for each Harness user, such as J_User_GitLab.

HTTPS/SSH

Select HTTPS or SSH for the connection. You will need to provide the protocol-relevant URL in URL.

If you use Two-Factor Authentication for your Git repo, connect over HTTS or SSH.

For SSH, ensure that the key is not OpenSSH, but rather RSA or another algorithm.

If you log into Bitbucket using a Google account, you can create an application password in Bitbucket to use with Harness. For steps on this, see App passwords from Atlassian.

To sync with GitLab, you will need to generate a SSH key pair and add the SSH key to your GitLab account. For more information, see Generating a new SSH key pair from GitLab.

URL

Enter the URL for your Git repo. Ensure it matches the option you selected in HTTPS/SSH.

Username and Password/Token

Enter the credentials for the repo user account.

If you have set up Two Factor Authentication in your Git repo, then you need to generate a personal access token in your repo and enter that token in the Password/Token field. In Github, you can set up the personal access token at https://github.com/settings/tokens/new.

SSH Key

If you selected SSH as the connection protocol, you must add the SSH Key for use with the connection. If you added a key in Harness Secrets Management, you can select it here. For more information, see Secrets Management.

To add a new key, click the drop-down and select Add New SSH Key. Paste in the key or key file path, enter a display name, and then click SUBMIT.

Branch Name

Enter the branch name to sync with Harness, such as master, dev, or myAppName. Do not enter the full URL to the branch.

Generate Webhook URL

Enable this checkbox if you want to sync Harness with your repo bidirectionally. Changes made on either end will be synched. If you simply want Harness changes synched unidirectionally with the repo, disable this checkbox.

When you use this Source Repo Provider to sync a Harness application to a repo bidirectionally, any account or application that uses this Source Repo provider will be synched bidirectionally. For more information, see Configuration as Code (GitOps).

Customize Commit Attributes (Git Sync Only)

When Harness commits or push a change to Git as part of synching, it uses Harness.io and support@harness.io as the author and commit email address of that commit.

In some cases, you might have strong pre-commit limitations on who may or may not commit. In that case, you need to provide an author name and email that is approved to push on that repo.

You can add an Author Name and Author Email address that will be applied whenever a synch with the Git repo is made by Harness.

Usage Scope

If you want to restrict the use of a provider to specific applications and environments, do the following:

In Usage Scope, click the drop-down under Applications, and click the name of the application.

In Environments, click the name of the environment.

Using the Webhook

If you selected the Generate Webhook URL option when adding your Source Repo Provider, the Generated Webhook URL dialog appears. Copy the URL and use it in your repo to enable your repo to sync changes to Harness.

GitHub
Modify the Content type to application/json and use the Just the push event trigger option:

Bitbucket

Use the Repository push event trigger.

For information on Bitbucket Webhooks, see Manage webhooks from Bitbucket.

Webhooks do not work with older versions of Bitbucket. You need to install the Post Webhooks for Bitbucket plugin in Bitbucket to enable Harness to allow two-way sync with Bitbucket.
GitLab

Use the Push events trigger.

Next Steps

Once a Source Repo Provider is set up, you can use it at the Harness account-level and application-level to sync your account and/or applications with your Git repo. For more information, see Configuration as Code.


How did we do?