Configure codebase
Configure the Git repository that your CI pipeline clones, and edit the default codebase settings.
CI pipelines build and test code that Harness pulls from a Git code repository. In Harness CI, you configure a codebase for your pipeline to define the Git repository that your Build stages clone at runtime. A Build stage clones the codebase automatically unless you disable Clone Codebase for that stage. When you add a Build stage to a pipeline that has no codebase yet, you can configure one.
What you will learn in this topic
In this topic, you learn how to:
Configure the default codebase for a pipeline.
Disable Clone Codebase for specific stages.
Edit the default codebase configuration, including advanced settings such as depth, clone strategy, LFS, sparse checkout, submodules, and pre-fetch commands.
Find troubleshooting information for codebases.
Before you begin
Before you start, make sure you understand the CI pipeline creation process.
Configure the default codebase
When you add a Build stage to a CI pipeline, you specify where your build code is stored. This location becomes the pipeline's default codebase.
In the Pipeline Studio, select Add Stage, and then select Build.
Enter a Stage Name. Description and Tags are optional.
Make sure Clone Codebase is enabled. This setting tells Harness to clone the codebase into the build environment before it runs the steps in the stage.
Configure your codebase connection.
To clone a repo from the Harness Code Repository module, select Harness Code Repository, and then select the repo to clone.
To clone a repo from a third-party Git provider, select Third-party Git provider, select the relevant code repo connector, and enter the name of the repo to clone if Repository Name is not automatically populated.
Select Set Up Stage.
To change the connector or other default codebase settings, go to Edit the default codebase configuration. If you do not want every stage to clone the default codebase, go to Disable Clone Codebase for specific stages. You can also clone multiple repositories in a stage.

Disable clone codebase for specific stages
After you define the default codebase in the first Build stage, you can disable Clone Codebase for individual stages that you add later. You can also disable cloning the default codebase, if necessary.
Disable Clone Codebase if the stage does not need the codebase, or if you need to use specific git clone arguments, such as to clone a subdirectory instead of an entire repo. You can also clone multiple code repos in a pipeline.
In the Visual editor, you disable Clone Codebase in the stage's Overview tab.

In the YAML editor, set cloneCodebase to false in the stage.spec.
Go to CI Build stage settings for Build stage settings.
Edit the default codebase configuration
To edit a pipeline's default codebase configuration, select Codebase on the right side panel of the Pipeline Studio's Visual editor.

To edit a pipeline's default codebase configuration in the YAML editor, edit the codebase section. For example:
In addition to changing the Connector (connectorRef) or Repository Name (repoName), you can edit the following Advanced settings.
Depth
The number of commits to fetch when the pipeline clones the codebase repo.
The default depth varies by build and trigger type:
For manually triggered branch and tag builds, the default depth is
50. Eachgit cloneoperation fetches the 50 most recent commits.For manually triggered PR builds and all auto-triggered builds, such as webhook triggers, the default depth is
0. Eachgit cloneoperation fetches all commits from the relevant branch.
Go to the git clone documentation for the full option reference.
Pull request clone strategy
When a pull request triggers a build, this setting determines the branch that Harness uses for the artifact after it clones the repo.
If you set this to Merge Commit, which is the default, the pipeline tries to merge the pull request branch with the target branch before it builds the artifact. This strategy guarantees that the artifact includes all commits in both the pull request and the target branch. The disadvantage is that the merge can take more time and cause build failures: if the merge fails, the build fails.

If you set this to Source Branch, the pipeline builds the artifact from the latest commit in the pull request branch. This strategy can be faster and less likely to cause build failures. However, the artifact might not include some commits in the target branch.

Clone directory
An optional target path in the pipeline workspace where you want to clone the repo.
You cannot specify /harness/ as a target directory for a Git Clone step because this folder is reserved for the Build stage's codebase. To share data across steps in your Build stage, specify Shared Paths in your CI Build stage settings.
Persist credentials (optional)
When you select this option, Harness persists the Git credentials that it uses during the clone step so they remain available for subsequent steps in the same build.
This option is useful when:
You need to run Git commands after the clone step, such as fetching submodules, tagging, or pushing commits.
You use a private Harness Code Repository or an authenticated third-party repository, and you want to avoid re-authenticating in every step.

Fetch tags
Determines whether to fetch all tags when you perform a shallow clone (depth > 0). Setting this to true is equivalent to adding the --tags flag.
Download LFS files
The Git Large File Storage (LFS) client is an extension for versioning large files, such as audio, video, datasets, and graphics.
Set Download LFS Files to true to download Git LFS files. The default is false. To run git lfs commands in a Run step instead, go to Git Large File Storage.
Sparse checkout
Performs a sparse checkout on the patterns you provide. You choose the subset of files by providing a list of directories in cone mode. Go to the git sparse-checkout documentation for the full pattern syntax.
Include submodules
Determines whether to include submodules in the clone. The default is false. Set this to true to include submodules, or to recursive to clone submodules recursively.
Pre fetch command
Specifies additional Git commands to run before Harness fetches the code. This field accepts Git commands only. Separate each command with a new line.
For example, you can use this field to set additional LFS configurations or to clone specific submodules:
Example: Partial clone
Git partial clone downloads commit and tree objects upfront but defers blob (file content) downloads until Git accesses those files. The full commit history is available for git log with no extra network calls. Operations that read file content, such as git blame, git show, and the checkout step that git bisect performs, trigger on-demand blob downloads as they access the files. Partial clone reduces the initial fetch size for large repositories.
Partial clone works with the Harness Code Repository module and any third-party Git provider that supports the partial clone protocol, such as GitHub, GitLab, and Bitbucket.
To enable partial clone, set depth: 0 so the clone is not shallow, and then add a preFetchCommand that runs git fetch with a --filter flag:
depth: 0 is required. If depth is greater than 0, the clone is shallow. Combining a shallow clone with a partial-clone filter is not supported and might produce unexpected results.
The expression <+codebase.branch> resolves to the codebase branch at runtime. You can also use a literal branch name, such as main or master. For pull request triggers, <+codebase.branch> resolves to the source branch of the PR. To fetch from the target branch instead, use <+codebase.targetBranch>.
You can substitute any --filter value that Git supports. For example:
Defer all blobs:
git fetch --filter=blob:none origin <+codebase.branch>downloads no blobs upfront and fetches each one on first access.Defer large blobs only:
git fetch --filter=blob:limit=100k origin <+codebase.branch>downloads blobs smaller than 100 KB upfront and defers the rest.
To review all supported filter values, go to the git rev-list --filter reference.
To verify that partial clone is active inside a build step, add a Run step that prints the following Git configuration values:
Git downloads blobs that it did not fetch upfront on demand the first time you access them, for example with git checkout, git show, or git blame.
Example: Conditional Git clean and reset
When you run builds on persistent workspaces, you might want to control whether each run discards untracked files or resets the working tree to the remote branch. An example is a shared path on a self-managed build infrastructure that retains the cloned repository across executions. You can drive this behavior from preFetchCommand with pipeline variables and conditional expressions, so a single pipeline supports both warm and clean runs without changes to the pipeline structure.
Declare two string pipeline variables and reference them in preFetchCommand with the ternary operator. If the variable resolves to the literal string "TRUE", the prefetch phase runs the corresponding Git command. Otherwise, it runs git --version as a no-op so the expression remains valid.
Behavior:
cleanVar == "TRUE": Runsgit clean -fdx, which removes all untracked files and directories, including ignored files. Use this setting to remove build artifacts and restore a clean working tree.resetVar == "TRUE": Runsgit fetch origin <branch>followed bygit reset --hard origin/<branch>, which moves the local branch pointer to the remote tip and discards any local commits or uncommitted changes.Neither variable set to
"TRUE": Both expressions resolve togit --version, which leaves the existing workspace untouched.
Important callouts:
Case-sensitive matching: The comparison uses strict string matching. Only the literal value
TRUEtriggers the command. Harness treats values such astrue,True, or1as false.Independent toggles: Harness evaluates
cleanVarandresetVarseparately. You can enable one, both, or neither per execution.Runtime overrides: Because the variables use
<+input>.default(...), you can overridecleanVar,resetVar, orbranchat runtime from the Run Pipeline form or from a trigger, or pin them through an input set.No-op fallback: The pipeline requires the
git --versionplaceholder so the ternary expression always produces a valid command line when the condition is false.
SSL verify
If you set this to 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 want to run your builds anyway.
To use self-signed certificates in a Kubernetes cluster build infrastructure, go to Configure a Kubernetes Build Farm to use Self-Signed Certificates.
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. Express memory as a plain integer or as a fixed-point number with the suffix
GorM. You can also use the power-of-two equivalentsGiandMi. The default is500Mi.Limit CPU: The maximum number of cores that the container can use. CPU limits use CPU units. Fractional values are allowed. For example, specify one hundred millicpu as
0.1or100m. The default is400m. Go to Resource units in Kubernetes in the Kubernetes docs.
Troubleshooting
Go to the Harness CI Knowledge Base for more common questions and issues related to codebases.
Go to SCM status checks for branch protection and status checks for codebases associated with Harness CI pipelines.
Go to Troubleshoot Git event triggers for troubleshooting information for Git event (webhook) triggers.
Next steps
Git Clone step in CI: Clone a repository into the stage's workspace.
Clone multiple code repos in one pipeline: Use Git Clone steps to clone additional repos.
Clone a subdirectory: Use a Run step to clone a subdirectory instead of an entire repo.
CI codebase variables reference: Reference Git codebase attributes with built-in expressions.
SCM status checks: Configure branch protection and status checks for your codebases.
Last updated
Was this helpful?