On this post I will give you an example of how to clone a repo into your pipeline and use it for other jobs.

As you can read from Gitlab official documentation artifact can output an archive of files/directories. I set the following example:


  artifacts:
    paths:
      - <project_name>
    exclude:
      - <project_name>/.git/**/*
    expire_in: 60 seconds

We need to call the artifacts by using “artifacts” keyboard in the pipeline, in this example paths keyboard which files/directories add into artifacts.

exclude prevents files from being added to an artifacts. In our example as we’re cloning a repo we will need to avoid the .git directory in order to avoid conflict thus

    exclude:
      - <project_name>/.git/**/*
    expire_in: 60 seconds

above I added <project_name> folder and excluded “.git/**/*” all .git folder and subfolders.

and expire_in this keyboard determines how long gitlab will keep this job artifact, as I just want to use it ones by each pipeline, I set it just to keep it 60s.

Then if you need to use this artifact in another job you need to add a dependencies as below:

building: 
  stage: building
  dependencies:
    - "clone"

I finally below you can see a full pipeline example:


stages:
- clone

clone:
  stage: clone
  before_script:
    - apt-get -qq update
    - apt-get -qq install -y git
  script:
    - git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.<company>/path/<project_name>.git
  artifacts:
    paths:
      - <project_name>
    exclude:
      - <project_name>/.git/**/*
    expire_in: 60 seconds