0

I'm working on a gitlab pipeline that among the other things should work with some file located in another gitlab repo. For now I do it like this:

script:
 - git clone https://gitlab-ci-token:${TOKEN}@${repo}.git  
 - cd repository
 - git checkout desired-branch  
 - cd desired/folder  
  #then perform the desired operations like: 
 - ls

Also if the previous code works it seems to me a waste of resources to clone every time the whole repo including all the folders, all the commits and all the branches when I'm just interested on a simple folder.
Is there a specific gitlab command that allows me to just download the desired files?
For example:

script:
 - git download  https://gitlab-ci-token:${TOKEN}@${repo}.git --f="desired-folder" --b="desired-branch"
 - ls

1 Answers1

1

You can solve some of your issues by (a) performing a shallow clone and (b) specifying your target branch in the clone command:

script:
  - git clone -b desired-branch --depth=1 https://...

By using a shallow clone, you are downloading only the HEAD commit and not the entire repository history. By using the -b <branch> option you're saving yourself from having to run git checkout desired-branch after the clone completes.


For a project hosted specifically on gitlab, there is generally a direct download link available for any given file. For example, take a look at this README file. There is a direct download link available available by clicking on the "download" icon on the right.

Using that facility, you could replace your git clone/cd/etc with a single curl command if all you need is a single file.

larsks
  • 277,717
  • 41
  • 399
  • 399