Git Clone

Clone a Git repository into pipeline runtime environment.

Git account and repository should be provided while creating a pipeline. The account and the repository will be automatically used in the Git Clone step while executing the pipeline.

Git Clone step uses Git accounts connected within Microtica Portal to obtain temporary access credentials.

Git credentials

Credentials for the specified Git repository will be automatically provided by Microtica.

#Syntax

YAML

steps:
  step-name:
    type: git-clone
    clone_dir: sub/folder/
ParameterDescriptionRequired
titleThe display name of the step.No
typeThe type of the Microtica built-in step.
Should always be git-clone for this type of step.
Yes
clone_dirPath to where the source code should be cloned.

Default: .
Current working dir of the pipeline runtime environment.
No
ssh_keyProvide a private SSH key to be used when cloning the source code from Git repository.

The key should be provided in base64 format.
You can encode the private key in base64 format using the following command where id_rsa is your private key:
cat ~/.ssh/id_rsa | base64

Default: null
No
clone_submodulesClone all submodules recursively for a given Git repository.

Default: false
No

#Clone a source code from a Git repository

When using the built-in step Git Clone, the Git account and repository provided while creating the pipeline will be automatically used in the step.

Create new pipeline

In the following example, the Clone step will clone the master branch from microtica/app repository hosted on Microtica Git account.

So, if you run ls -l command in the next step you should be able to see the content of the source code root dir.

microtica.yaml

steps:
  Clone:
    type: git-clone
  ListContent:
    image: alpine:latest
    commands:
      - ls -l

#Clone into sub directory

By default the source code will be cloned in the current working dir of the pipeline runtime environment. If you need to store the code in a different directory you can achieve that by using clone_dir parameter.

microtica.yaml

steps:
  Clone:
    type: git-clone
    clone_dir: sub/folder
  ListContent:
    image: alpine:latest
    commands:
      - cd sub/folder
      - ls -l

So, if you navigate to sub/folder and run ls -l command in the next step you should be able to see the content of the source code root dir.

#Use an SSH key with Git

If you prefer to use an SSH key to access the Git repository you can achieve this by providing your SSH key as pipeline sensitive environment variable with key ssh_key.

To encode the private key in base64 format use the following command where id_rsa is your private key:

cat ~/.ssh/id_rsa | base64

Copy and paste the encoded key into pipeline variable.

Pipeline environment variables
Security consideration

Please make sure that you enable Sensitive option for the SSH key environment variable. This way the value will be stored and processed in a secure storage instead of plain value.

If you want to use a different environment variable key then ssh_key you can do that by using a step parameter and reference the pipeline environment variable. Below is an example step specification:

microtica.yaml

steps:
  Clone:
    type: git-clone
    ssh_key: "{{MY_SSH_KEY_ENV_VAR}}"

Where MY_SSH_KEY_ENV_VAR is the environment variable key defined in the Microtica pipeline.