Harness Git Experience Quickstart
NG_GIT_EXPERIENCE. Contact Harness Support to enable the feature.
This quickstart shows you how to enable and use Git Experience for your Harness resources, such as Pipelines.
Harness Git Experience lets you store your resources and configurations in Git and pick Git repos as the source of truth.
You'll learn how to:
- Enable Git Experience for a Pipeline.
- Create and sync a Pipeline with your Git repo.
- Execute a Pipeline
Before You Begin
Make sure you have the following set up before you begin this quickstart:
- Make sure you have a Git repo with at least one branch.
- Make sure you have a Git connector with a Personal Access Token (PAT) for your Git account.
- A Personal Access Token (PAT) for your Git account.
- Harness needs the PAT to use the Git platform APIs.
- You add the PAT to Harness as a Text Secret and it is encrypted using a Harness Secret Manager.
- Your Git Personal Access Token is stored in your Harness secret and is a private key to which only you have access. This secret cannot be accessed or referenced by any other user.
- The PAT must have the following scope:
- To enable Git Experience for your resources, make sure that you have Create/Edit permissions for them.
Supported Git Providers
The following section lists the support for Git providers for Harness Git Sync:
- Bitbucket Cloud
- Azure Repos
Review: Git Experience Requirements
You can store your resources and configurations in Git by selecting the Remote option while creating the resources.
For this, you must specify a Harness Git Connector, a repo, branch details, and file path.
This topic explains how to create a remote Pipeline and execute it using Harness Git Experience.
You can also store your configurations in Harness, by selecting the Inline option while creating resources. For more information on creating an inline Pipeline, see Pipelines and Stages.
You can store configurations of the following resources in Git:
- Input Sets
Harness tracks where your configuration is kept and manages the whole lifespan of resources by maintaining metadata for each resource.
Step 1: Add a Remote Pipeline
This quickstart explains how to add a Pipeline and sync it with your Git repo. This is called the Remote option. To add an inline Pipeline, see Remote option. To add an inline Pipeline, see Create a Pipeline.
In your Project, click Pipelines and then click Create a Pipeline. The Create New Pipeline settings appear.
Click Remote. The additional settings appear to configure Git Experience.
In Select Git Connector, select or create a Git Connector to the repo for your Project. For steps, see Code Repo Connectors.
Important: Connector must use the Enable API access option and Token
For GitHub, the token must have the following scopes:
Here's an example of a GitHub Connector that has the correct settings:
In Select Repository, select or enter your repository.
In Git Branch, select or enter your branch.
Harness auto-populates the YAML Path. You can change this path and the file name. All your configurations are stored in Git in the Harness Folder.
.harness/and is unique.
The Pipeline Studio is displayed with your repo and branch name.
Step 2: Add a Stage
Click Add Stage. The stage options appear.
Select a stage type and follow its steps.
The steps you see depend on the type of stage you selected.
For more information, see Add Stage.
Add a step and click Save.
The Save Pipelines to Git settings appear.
In Select Branch to Commit, commit to an existing or new branch.
- Commit to an existing branch: you can start a pull request if you like.
- Commit to a new branch: enter the new branch name. You can start a pull request if you like.
Click Save. Your Pipeline is saved to the repo branch.
Click the YAML file to see the YAML for the Pipeline.
Edit the Pipeline YAML. For example, change the name of a step.
Commit your changes to Git.
Return to Harness and refresh the page.
A Pipeline Updated message appears.
The changes you made in Git are now applied to Harness.
Step 3: Execute Pipeline
In your Project, click Pipelines.
Click on your Pipeline.
Select the branch from which you want to execute your Pipeline.
Your Pipeline is ready to run from the branch you just selected.
Click Run Pipeline.
During Pipeline execution, the configurations of the required resources and any referenced entities like Input Sets, are fetched from Git.
If the referenced entities exist in the same repo, they are fetched from the same branch that you have selected for Pipeline execution.
If the referenced entities exist in a different repo, they are fetched from the default branch of the repo where the entities are stored.
Harness resolves all the dependencies and then proceeds with Pipeline execution.