Skip to main content

Create and configure a codebase

CI pipelines build and test code that is pulled from a Git code repository. When you add a Build stage to a CI pipeline, you select a code repo connector that connects to the Git account or repository where your code is stored. This topic explains how to configure codebase settings for CI pipelines.

This topic assumes you have an understanding of Harness CI concepts and the general pipeline creation process.

Code repo connectors

Harness uses code repo connectors to connect to Git providers, such as Bitbucket, GitHub, GitLab, and others. You can create code repo connectors for entire accounts or specific repositories. You can view a list of your saved connectors in Connectors under Project Setup. The following topics provide more information about creating code repo connectors:

The CodeCommit, Bitbucket, GitHub, and GitLab Connectors have authorization settings as required by their respective providers. The Git connector can connect with any provider using basic authentication over HTTPS.

Configure a pipeline's default codebase

When you add a Build stage to a CI pipeline, you select a code repo connector that connects to the Git account or repository where your code is stored.

  1. In the Pipeline Studio, select Add Stage, and then select Build.
  2. Enter a Stage Name. Description and Tags are optional.
  3. Make sure Clone Codebase is enabled. This tells Harness to clone the codebase into the build environment before running the steps in the stage.
  4. For Connector, select or create a code repo connector.
  5. If Repository Name is not automatically populated, you can specify a repository to use for this pipeline. You can also set this field to <+input> to specify a repo at runtime.
  6. Select Set Up Stage.

Configuring the codebase when adding a Build stage.

The first codebase declared in a pipeline becomes the pipeline's default codebase. If you need to change the connector or other codebase settings, go to Edit the default codebase configuration.

Once a default codebase is established, when you add subsequent stages to the pipeline, you can disable Clone Codebase for those stages, but you can't change the connector or repo. Usually, you disable Clone Codebase only if the codebase is not needed for the stage's operations. However, you can also use a Git Clone step to clone multiple code repos in a pipeline.

Edit the default codebase configuration

To manage a pipeline's default codebase configuration, select Codebase on the right side panel while viewing the pipeline in the Pipeline Studio.

Configuring pipeline codebase settings.

In addition to changing the Connector or Repository Name, you can manage the following advanced settings.


The number of commits to fetch when the pipeline clones the codebase repo.

For manually-triggered builds, the default depth is 50. This means each git clone operation fetches the 50 most recent commits. For all other trigger types, the default depth is 0, which fetches all commits from the relevant branch.

For more information, go to the git clone documentation.

SSL Verify

If True, which is the default value, the pipeline verifies your Git SSL certificates. The build fails if the certificate check fails. Set this to False only if you have a known issue with the certificate and you are willing to run your builds anyway.

If you want to use self-signed certificates in a Kubernetes Cluster build infrastructure, go to Configure a Kubernetes Build Farm to use Self-Signed Certificates

Pull Request Clone Strategy

When a build is triggered by a pull request, this setting determines the branch to use for the artifact after the repo is cloned.

If this is set to Merge Commit (which is the default setting), the pipeline tries to merge the pull request branch with the target branch before building the artifact. This guarantees that the artifact includes all commits in both the pull request and the target branch. The disadvantage is that this can take more time and result in build failures: If the merge fails, then the build fails.

If this is set to Source Branch, the pipeline builds the artifact from the latest commit in the pull request branch. This can be faster and less likely to result in build failures; however, it might not include some commits in the target branch.

Set Container Resources

Set maximum resource limits for the containers that clone the codebase at runtime:

  • Limit Memory: The maximum memory that the container can use. You can express memory as a plain integer or as a fixed-point number using the suffixes G or M. You can also use the power-of-two equivalents Gi and Mi. The default is 500Mi.
  • Limit CPU: The maximum number of cores that the container can use. CPU limits are measured in CPU units. Fractional requests are allowed; for example, you can specify one hundred millicpu as 0.1 or 100m. The default is 400m. For more information, go to Resource units in Kubernetes.

YAML example

Here's an example of codebase configuration in YAML.

name: tutorial example
identifier: tutorial_example
projectIdentifier: tutorial_test
orgIdentifier: default
tags: {}
connectorRef: account.docsexample
build: <+input>
depth: 0
sslVerify: true
prCloneStrategy: MergeCommit
memory: 500Mi
cpu: 400m


Improve codebase clone time

If cloning your codebase takes more time than expected, try setting Limit Memory to 1Gi.

If codebase cloning takes longer than expected when the build is triggered by a pull request, set Pull Request Clone Strategy to Source Branch and set Depth to 1.

The same Git commit is not used in all stages

If your pipeline has multiple stages, each stage that has Clone codebase enabled will clone the codebase during stage initialization. If your pipeline uses the generic Git connector and a commit is made to the codebase after a pipeline run has started, it is possible for later stages to clone the newer commit, rather than the same commit that the pipeline started with.

If you want to force all stages to use the same commit ID, even if there are changes in the repository while the pipeline is running, you must use a code repo connector for a specific SCM provider, rather than the generic Git connector.

See also