Checking out Git repositories
Using the Codefresh native GIT integration
Codefresh has native support for GIT repositories and Git triggers. First you need to setup a GIT integration (Your administrator might also have done this for you already).
You can add new integration for any cloud provider or even on-premise ones. By default you will also have a provider setup if you used one for Codefresh signup (Github, Gitlab or Bitbucket).
For each Git Integration, make sure that you note down its name, as you will use in your pipeline inside a git-clone step.
Cloning a specific repository
The simplest way to clone using your git provider is by specifying the exact repository details. Here is a pipeline that clones a git repository and creates a Docker image from a Dockerfile:
This syntax is very simple to use, but it has the disadvantage that ties your pipeline to a specific repository. This makes the pipeline impossible to re-use among different micro-services (that are built in a similar manner).
Cloning the triggered repository (recommended)
The proper way to use git-clone steps is to make them trigger specific. Instead of hard-coding the git repository that is checked-out, it is best to checkout the same one that triggered the pipeline. This is what you want in most scenarios anyway.
This can be achieved by using Codefresh variables to refer to the trigger. Here is the same pipeline as before, written in a generic way:
The big advantage of this pipeline is that it can be reused for ALL your projects that follow the same pattern of having a Dockerfile in the root of the git repository.
Thus you can have a single pipeline and when you want to enable it for a new micro-service you can simply add a new git trigger for it.
You still run the pipeline manually if you wish. In this case you will be asked which trigger you want to “simulate” so that the variable pipelines are correctly replaced by Codefresh.
This is the recommended way of creating re-usable pipelines in Codefresh.
Cloning a repository using the Codefresh runner
More details can be found in the private Git instructions page.
Working inside the cloned directory
Normally each pipeline step in Codefresh can be named as you want. Specifically, for the git-clone step however the name
main_clone is special.
If you name your clone step as
main_clone the Codefresh will automatically change the working directory for all the next (non git-clone) pipeline steps, to be the same as the project that was just checked out.
This is probably what you want anyway, so make sure that you name your git-clone steps as
main_clone. If you use any other name, then the working folder will be the parent of the checked-out project which is the shared Codefresh volume at
If you have more then one clone steps in a pipeline it is recommended to define the working directory explicitly (see next example), instead
of depending on the
main_clone naming convention, which is best used in pipelines with a single clone step.
Cloning multiple repositories
You can use as many clone steps as you want and at any position in the pipeline. They don’t have to be the first step.
Here is an example where two repositories are checked out and two docker images are then built.
Notice that in this case the git-clone steps are not named
main_clone and therefore we specify exactly what is the working directory for each one.