Customizing the git checkout process
Clones a Git repository to the filesystem.
Note that this step is completely optional. Codefresh will automatically checkout the code from a connected git repository when a pipeline is created on that repository.
||The free-text display name of the step.||Optional|
||A basic, free-text description of the step.||Optional|
||Parent group of this step. See using stages for more information.||Optional|
||The directory to which the repository is cloned. It can be an explicit path in the container’s file system, or a variable that references another step. The default value is
||The name of the git integration you want to use. You can also use
||path of the repository without the domain name in the form of
||The revision of the repository you are checking out. It can be a revision hash or a branch name. The default value is
||Credentials to access the repository, if it requires authentication. It can an object containing
||If a step fails and the process is halted. The default value is
||Define a set of conditions that need to be satisfied in order to execute this step. You can find more information in the Conditional Execution of Steps article.||Optional|
||Define operations to perform upon step completion using a set of predefined Post-Step Operations.||Optional|
||Define retry behavior as described in Retrying a step.||Optional|
- Working Directory
If you want to extend the git-clone step you can use the freestyle step. Example how to do it you can find here
Skip or customize default clone
A git clone step is transparently added to git attached pipelines without you having to explicitly add a step into the pipeline. This is a convenience to enable easy CI pipelines.
If you do not require git cloning, or you would like to customize the implicit git cloning behaviour, you can choose to skip the automatically added git clone step.
There are 2 ways to do that:
- Add a pipeline environment variable called
CF_SKIP_MAIN_CLONEwith value of
- Add a step with key
main_cloneto your pipeline. This step can be of any type and can do any action. This step will override the default clone implementation. for example:
version: '1.0' steps: main_clone: title: Checking out code image: alpine/git:latest commands: - git clone ... another_step: ...
Reuse a Git token from Codefresh integrations
If you customize the git clone step, you also have the capability to use one of your existing git integrations as an authentication mechanism.
Here is an example for Github
version: '1.0' steps: get_git_token: title: Reading Github token image: codefresh/cli commands: - cf_export GITHUB_TOKEN=$(codefresh get context github --decrypt -o yaml | yq -y .spec.data.auth.password) main_clone: title: Checking out code image: alpine/git:latest commands: - git clone https://my-github-username:$GITHUB_TOKEN@github.com/my-github-username/my-repo.git another_step: ...
Working with GIT submodules
To use this module in your pipeline add a new step like the one shown below.
version: '1.0' steps: updateSubmodules: image: codefresh/cfstep-gitsubmodules environment: - GITHUB_TOKEN=<github_token> - CF_SUBMODULE_SYNC=<boolean to determine if modules should be synced> - CF_SUBMODULE_UPDATE_RECURSIVE=<boolean to determine if modules should be recursively updated>
The Github token can be either defined in the pipeline on its own as an environment variable, or fetched from the existing GIT integration as shown in the previous section.
Use an SSH key with Git
It is also possible to use an SSH key with git. When creating your pipeline add your SSH key as an encrypted
environment variable after processing it with
cat ~/.ssh/my_ssh_key_file | tr '\n' ','
Then in pipeline use it like this: