using gitlab token to clone without authentication

前端 未结 14 2629
失恋的感觉
失恋的感觉 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:35

    Customising the URL is not needed. Just use a git configuration for gitlab tokens such as

    git config --global gitlab.accesstoken {TOKEN_VALUE}
    

    extended description here

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

    I know this is old but this is how you do it:

    git clone https://oauth2:ACCESS_TOKEN@somegitlab.com/vendor/package.git

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

    These days (Oct 2020) you can use just the following

    git clone $CI_REPOSITORY_URL
    

    Which will expand to something like:

    git clone https://gitlab-ci-token:[MASKED]@gitlab.com/gitlab-examples/ci-debug-trace.git
    

    Where the "token" password is ephemeral token, it should be revoked after a build is complete.

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

    To make my future me happy: RTFM - don't use the gitlab-ci-token at all, but the .netrc file.

    There are a couple of important points:

    1. echo -e "machine gitlab.com\nlogin gitlab-ci-token\npassword ${CI_JOB_TOKEN}" > ~/.netrc
    2. Don't forget to replace "gitlab.com" by your URL!
    3. Don't try to be smart and create the .netrc file directly - gitlab will not replace the $CI_JOB_TOKEN within the file!
    4. Use https://gitlab.com/whatever/foobar.com - not ssh://git@foobar, not git+ssh://, not git+https://. You also don't need any CI-TOKEN stuff in the URL.
    5. Make sure you can git clone [url from step 4]

    Background: I got

    fatal: could not read Username for 'https://gitlab.mycompany.com': No such device or address
    

    when I tried to make Ansible + Gitlab + Docker work as I imagine it. Now it works.

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

    You can use the runners token for CI/CD Pipelines of your GitLab repo.

    git clone https://gitlab-ci-token:<runners token>@git.example.com/myuser/myrepo.git
    

    Where <runners token> can be obtained from:

    git.example.com/myuser/myrepo/pipelines/settings
    

    or by clicking on the Settings icon -> CI/CD Pipeline and look for Runners Token on the page

    Screenshot of the runners token location:

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

    I went SSH using the per project deploy keys setting (read only)

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