How to clone a private git repository using Gitlab CI

Viewed 587

Scenario: I've created two repositories inside my GitLab account: 'work' & 'project'. There are multiple branches in each of the following repos. I'm currently in the project repo and have created the .gitlab-ci.yml file.

Task: I want to copy two files 'A' & 'B' from the feature branch of 'work' repository to the current location (i.e., in the root of my project repository).

Thanks in advance :)

1 Answers

It's very easy, just add it to your script section - git clone https://user:password@gitlab.com/group/project.git

Or to download specific files - curl --header 'Private-Token: <your_access_token>' https://gitlab.com/api/v4/projects/:id/repository/files/:filename\?ref\=:ref

Also it will be a great practice to add Private-Token to project masked varible

You can get access token here access_token

Related