using gitlab token to clone without authentication

前端 未结 14 2627
失恋的感觉
失恋的感觉 2020-11-28 17:56

I want to clone gitlab repository without prompt for my automation script, by using my private token from my gitlab account.

Can someone provide me a sample?

<
相关标签:
14条回答
  • 2020-11-28 18:21

    As of 8.12, cloning using HTTPS + runner token is not supported anymore, as mentioned here:

    In 8.12 we improved build permissions. Being able to clone project using runners token it is no supported from now on (it was actually working by coincidence and was never a fully fledged feature, so we changed that in 8.12). You should use build token instead.

    This is widely documented here - https://docs.gitlab.com/ce/user/project/new_ci_build_permissions_model.html.

    0 讨论(0)
  • 2020-11-28 18:25

    Use the token instead of the password (the token needs to have "api" scope for clone to be allowed):

    git clone https://username:token@gitlab.com/user/repo.git
    

    Tested against 11.0.0-ee.

    0 讨论(0)
  • 2020-11-28 18:25

    Inside a GitLab CI pipeline the CI_JOB_TOKEN environment variable works for me:

    git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/...
    

    Source: Gitlab Docs

    BTW, setting this variable in .gitlab-ci.yml helps to debug errors.

    variables:
        CI_DEBUG_TRACE: "true"
    
    0 讨论(0)
  • 2020-11-28 18:29

    One possible way is using a deploy token (https://docs.gitlab.com/ee/user/project/deploy_tokens). After creating the token, use:

    git clone https://<username>:<deploy_token>@gitlab.example.com/tanuki/awesome_project.git 
    

    as mentioned in the link above.

    0 讨论(0)
  • 2020-11-28 18:31

    If you already has a repository and just changed the way you do authentication to MFA, u can change your remote origin HTTP URI to use your new api token as follows:

    git remote set-url origin https://oauth2:TOKEN@ANY_GIT_PROVIDER_DOMAIN/YOUR_PROJECT/YOUR_REPO.git

    And you wont need to re-clone the repository at all.

    0 讨论(0)
  • 2020-11-28 18:34

    The gitlab has a lot of tokens:

    • Private token
    • Personal Access Token
    • CI/CD running token

    I tested only the Personal Access Token using GitLab Community Edition 10.1.2, the example:

    git clone https://gitlab-ci-token:${Personal Access Tokens}@gitlab.com/username/myrepo.git
    
    
    git clone https://oauth2:${Personal Access Tokens}@gitlab.com/username/myrepo.git
    

    or using username and password:

    git clone https://${username}:${password}@gitlab.com/username/myrepo.git
    

    or by input your password:

    git clone https://${username}@gitlab.com/username/myrepo.git
    

    But the private token seems can not work.

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