Clone a subdirectory
If you want to clone a subdirectory instead of your entire Git repo, you can disable the pipeline's default codebase and then run your git
commands in a Run step.
You can also use this pattern if you need to use specific git clone
arguments to clone your codebase.
This topic explains how to use a Run step to run specific git clone
arguments (such as --recursive
or sparse-checkout
) instead of using the built-in clone codebase functionality.
Disabling the built-in clone step removes access to some associated functionality, such as PR status updates or resolution of <+codebase.*>
expressions.
Determine if you need to disable Clone Codebase
- Clone with my git commands instead of using the built-in clone step: If Clone Codebase is enabled, then the build clones the pipeline's default codebase automatically. If you don't want to clone the default codebase, you must disable Clone Codebase so that you can clone the repo with your desired
git
commands. - Clone with my git commands and use the built-in clone step: If you want to clone files from another repo in addition to the default codebase, then do not disable Clone Codebase. For this pattern, follow the instructions in Clone multiple code repos in one pipeline and use the Run step option.
Add a Run step with git commands
Add a Run step containing your desired git
commands, such as git sparse-checkout
to clone a subdirectory instead of an entire repo.
- step:
type: Run
identifier: clone
name: clone
spec:
shell: Sh
command: |-
git sparse-checkout ...
Store tokens and passwords as Harness secrets and use variable expressions, such as <+secrets.getValue("YOUR_TOKEN_SECRET")>
, to call them in your commands.