Harness Git Experience Quickstart
This quickstart shows you how to enable and use Harness Git Experience.
Harness Git Experience integrates your Harness Projects, Pipelines, and resources with your Git repos. You can manage and run your Harness Pipelines and resources entirely from Git or use a hybrid method. With Harness Git Experience, your Git repos are always the single source of truth.
You'll learn how to:
- Connect your SCM to Harness.
- Enable Harness Git Experience in a new Project.
- Create and sync a new Pipeline with your Git repo.
Before You Begin
You'll need a Git repo with at least one branch and a Personal Access Token (PAC) for your account. Harness needs the PAC to use the Git platform APIs. The PAC is encrypted using a Harness Secret Manager.
Here's a quick walkthrough of enabling and using Harness Git Experience:
Step 1: Add a Source Code Manager
A Harness Source Code Manager (SCM) contains your personal account for a Git provider such as GitHub or AWS CodeCommit. You can add one SCM to your account for each provider.
In Harness, click your account profile in the bottom of the navigation.
In My Source Code Managers, click Add Source Code Manager.
In Add a Source Code Manager, enter a name for the SCM.
Select the SCM type, such as GitHub.
Enter the authentication credentials.
We'll use GitHub in this example, but you can find the settings for all of the SCMs in Source Code Manager Settings.
Here's a GitHub example:
Click Add. The new SCM is listed under My Source Code Managers.
Step 2: Enable Git Experience in a Project
In the Git provider you want to use for syncing your Project, create a repo(s) for the Project.
In the repo, add a folder named projects.
For this example, we'll use one repo and the folder named projects.
Here's a new GitHub repo named GitExpDocExample.
In Harness, create a new Project. See Create Organizations and Projects.
Here's a new Project named GitExp Doc Example.
When you're done you'll have a new Project containing the modules according to your license.
In your Project, click Project Setup, and then click Git Management.
Enable Git Experience appears.
Click Enable Git Experience.
The Configure Harness Folder settings appear.
The Harness Folder is the default folder for the repo where you are syncing your Project.
The Harness Folder is named .harness. This allows you to identify Harness Project YAML files in your repos.
Later, when you add Pipelines and resources to this Project, you can specify their default folders. When a Pipeline in one repo needs to access a Connector/Secret/etc in another repo at runtime, the Pipeline will always use the Connector/Secret/etc in their default branch and folder.
You can add the Project's Harness Folder at the root of your repo or in a subfolder.
In Repository name, enter a name for the repo. It doesn't have to be the same as the Git repo name. The name you enter here will appear in Harness only. It'll identify the Project repo.
For example, here's the Repository name
GitExpDocExample after Harness Git Experience is enabled:
In Select Connector, select or create a Git Connector to the repo for your Project. For steps, see Code Repo Connectors.
Here's an example of a GitHub Connector that has the correct settings:
Once you add a Connector, in Repository URL, you should see the repo URL.
Click Test Connection. Once Harness verifies the connection, you will see Connection Successful.
In Select Harness Folder, enter the name of the folder in your repo where you want to sync.
In Select Default Branch, select the branch that you want to use, such as main.
Here's an example of the Configure Harness Folder settings for a repo and folder:
When you're ready, click Save.
In Select Connectivity Mode, you have two options:
- Connect Through Manager: Harness SaaS will connect to your Git repo whenever you make a change and Git and Harness sync.
- Connect Through Delegate: Harness will make all connections using the Harness Delegate. This option is used for Harness On-Prem frequently, but it is also used for Harness SaaS.
For this quickstart, select Connect Through Manager, and then click Save and Continue.
Harness Git Experience is enabled and the new repo and folder are listed:
Step 3: Review the Harness Git Experience in your Project
Harness does not automatically add a folder to your repo until you create a Pipeline or resource like a Connector in your Project.
You can see the repo setting in your Project before creating Pipelines and resource.
In your Project, click one of you modules. In this example, we'll use Builds.
At the top of the page you can see All Repositories.
Click All Repositories and select the name of the repo you entered in Repository name earlier.
You can now select any branches from the repo.
Harness Git Experience is enabled!
Step 4: Add a Pipeline
Now you can create Pipelines and resources and store their YAML files in your Git repo's branches and folders.
Git is the single source of truth. The Pipelines and resources are stored in the repo first, and then synced with Harness.
In your Harness Project, click Builds. If you don't have the Builds module, use another module.
In Builds, click Pipelines.
At the top of the page is All Repositories.
You select the repo and branch here to display the Pipelines stored in them. It does not affect the repo and branch where you create a new Pipeline. You will select that repo and branch in the Create New Pipeline settings next.
Click +Pipelines to create a new Pipeline. The Create New Pipeline settings appear.
Give the Pipeline a name such as Example.
In Git Repository Details, select the repo and branch where you want to store the Pipeline YAML file in. You will select a folder in that repo and branch later.
We're simply demonstrating Harness Git Experience so we'll create a very simple Pipeline.
Click Add Stage and then click Build.
In About Your Stage, enter the name helloworld.
Disable Clone Codebase.
Click Set Up Stage.
Next, you can just paste the following YAML into the Pipeline to create a very simple Pipeline.
Click YAML and then paste in the follow YAML.
command: echo "hello world"
projectIdentifier: GitExp_Doc_Example with identifier of your Project.
You can see the Project ID right after
projects in the URL of the page:
The Pipeline is ready. Now we can save it to Git.
Step 5: Save the Pipeline to Git
When you click Save, the Save Pipelines to Git settings appear.
In Harness Folder, select one of the folders set up in the Project's Git Experience settings.
The YAML file for the Pipeline will be saved to this folder. But you can add subfolders in File Path.
In File Path, enter a name for the YAML file, such as
Example.yaml. Harness will generate one automatically from the Pipeline name, but you can add your own.
To enter a subfolder of the Harness Folder you selected, enter the folder name in front of the file name like
In this example, we use
In Commit Details, enter a message.
In Select Branch to Commit, commit to an existing or new branch.
- Existing branch: you can start a pull request if you like.
- New branch: enter the new branch name. You can start a pull request if you like.
Here's a simple example:
The Pipeline is saved to the repo branch and folder.
Step 6: View the Pipeline in Git and Harness Git Experience
In your Git repo, locate the branch, folder, and file.
Harness created a .harness folder under the folder you selected in Harness Folder.
If you added a folder to File Path, open that folder.
Click the YAML file for your Pipeline. The YAML is displayed.
In your Harness Project, click Project Setup, and then click Git Management.
In Git Management, click Entities.
In Entities by repositories, expand the Project name.
The Pipeline is listed along with its file path in the repo.
Now you have a Pipeline stored in Git.
Congratulations! You now have Harness Git Experience set up, synced with your Git repo, and storing a new Pipeline.
Next, explore other Harness features: