Add a GitLab Repo

Updated 1 month ago by Michael Katz

This topic outlines how to start syncing your Harness account and applications with one or more GitLab repositories. You add these repos as Source Repo Providers in Harness, as covered below:

Before You Begin

Limitations

  • One Harness Application cannot be in multiple repos.
  • 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—for example, a connection to an Artifact Server or Cloud Provider—Harness will not sync with your Git repo.

Step 1: Add Source Repo Provider

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 settings appear.

Step 2: Display 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.

Step 3: 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 HTTPS or SSH.

For SSH, ensure that the key is not OpenSSH, but rather RSA or another algorithm. To generate an SSHv2 key, use: 
ssh-keygen -t rsa -m PEM 
The rsa and -m PEM ensure that the key is RSA.
Next, follow the prompts to create the PEM key. For more information, see the  ssh-keygen man page and Connecting to GitHub with SSH.

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.

Step 4: URL

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

Step 5: Username and Password/Token

In Select Encrypted Password/Token, select or create a new Harness Encrypted Text secret for the credentials of your Gitlab 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.

Step 6: 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. The SSH Configuration dialog appears.

In User Name, enter git. Ensure that it is lowercase.

git is the only value you should use in User Name.

In Credentials, paste in the key or key file path, enter a display name, and then click Submit.

Step 7: 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.

Step 8: Generate Webhook URL

Enable this checkbox if you want to sync Harness with your repo bidirectionally. Changes made on either end will be synced. 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 synced bidirectionally. For more information, see Configuration as Code.

Step 9: Customize Commit Attributes (Git Sync Only)

When Harness commits or pushes a change to Git as part of syncing, 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 Harness syncs with the Git repo.

Option: 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.

GitLab

Use the Push events trigger.

Step 10: Test and Save

To finish configuring this Source Repo Provider:

  1. In the Git Connector settings, click Test. Harness verifies the settings you entered.
  2. When testing is successful, click Submit. This Source Repo Provider is now added to Harness.

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. See Configuration as Code.

  • To trigger Harness workflows and pipelines using Git Webhooks, see Add a Trigger.


How did we do?