Download a GitLab private repository

前端 未结 5 853
北恋
北恋 2020-12-14 02:50

I want to use curl to download my private repo in GitLab. I know I can use the Gitlab API, but for some reason, It doesn\'t work.

Is this possible? When

相关标签:
5条回答
  • 2020-12-14 03:10

    You can, but you need to authenticate yourself (as in "Gitlab API: How to generate the private token")

    curl http://gitlab.server/api/v3/session --data 'login=myUser&password=myPass'
    

    Then with the private token:

    curl --header "PRIVATE-TOKEN: QVy1PB7sTxfy4pqfZM1U" "http://example.com/api/v3/projects"
    

    Or, in your case, get the repository files:

    GET /projects/:id/repository/files
    

    Or, download directly one file.

    0 讨论(0)
  • 2020-12-14 03:13

    Provided you have your own "Personal Access Token" (as described in other answers) you can download an archive of your repository's branch by using the curl command:

    curl -k --header "PRIVATE-TOKEN: xxxx" https://gitlab.xxxxx/api/v4/projects/<projectID>/repository/archive?sha=630bc911c1c20283d3980dcb95fd5cb75479bb9c -o myFilename.tar.gz
    

    ProjectID is displayed on the repo's main page. You can obtain the SHA value from the webUI after selecting the branch you want from the pull-down and copying the value on the right for the SHA. See screenshot below:

    The other way to do this is via wget like this:

    wget --no-check-certificate -O myFilename.zip --header=PRIVATE-TOKEN:xxxx "https://gitlab.xxxx/api/v4/projects/<projectID>/repository/archive.zip?sha=630bc911c1c20283d3980dcb95fd5cb75479bb9c"
    

    I hope that helps.

    0 讨论(0)
  • 2020-12-14 03:14

    This is possible, just follow these steps:

    1. First, you have to create a "Personal Access Token":

      1. Go to Your Profile > Settings > Access Tokens.
      2. Enter a name for your "Personal Access Token".
      3. Check "api Access the authenticated user's API"

      4. Click "Create personal access token"

      5. The page will reload and save your new token.
      6. Make sure you save the token somewhere safe, you won't be able to view it again.

    2. Now that you have your "Personal Access Token", you need to get your project id to use the API:

      1. Go to https://gitlab.com/api/v3/projects?private_token=XXXXXXXXXXXXXXXXXXXX (replace the Xs with your new token)
      2. Get your project's id from the json.

    3. Now you can call:

      wget -O your_project.tar.gz https://gitlab.com/api/v3/projects/0000000/repository/archive?private_token=XXXXXXXXXXXXXXXXXXXX

    And that'll download your project as a .tar.gz file.

    0 讨论(0)
  • 2020-12-14 03:25

    You can use the private token that is yours (found in "profile settings") to access any resource. Just browse to the repository file you want to download, copy the "raw" file link and append ?private_token=...

    Example:

    curl https://git.local/user1/myrepo/raw/master/myfile.txt?private_token=ahgiretherghaeoi
    
    0 讨论(0)
  • 2020-12-14 03:28

    If you need to do this in a CI run and your private repo is on the same server, you should be able to use git submodules to clone other repos at the same time. Using the ${CI_JOB_TOKEN} is another option since GitLab 8.12.

    0 讨论(0)
提交回复
热议问题