Can't clone private repo with CI_JOB_TOKEN in CI

:hugs: Please help fill in this template with all the details to help others help you more efficiently. Use formatting blocks for code, config, logs and ensure to remove sensitive data.

Problem to solve

Describe your question in as much detail as possible:

  • What are you seeing, and how does that differ from what you expect to see?
    I have two projects which base on golang language
    groupA/projectA:public project
    groupA/projectB:private project
    the gitlab-ci.yml in projectA has a job that execute
    echo -e "machine git.domain.cn\nlogin gitlab-ci-token\npassword ${CI_JOB_TOKEN}" > ~/.netrc
    git config --global url."http://git.domain.cn/".insteadOf "git@git.domain.cn:"
    git clone http://git.domain.cn/groupA/projectB.git script.

  • Consider including screenshots, error messages, and/or other helpful visuals
    Error message like : remote: The project you were looking for could not be found or you don't have permission to view it. fatal: repository 'http://git.domain.cn/groupA/projectB.git/' not found. Both projects has open Allow access to this project with a CI_JOB_TOKEN Permission in CI/CD setting.

Steps to reproduce

Which troubleshooting steps have you already taken? Can you link to any docs or other resources so we know where you have been?

Configuration

Add the CI/CD configuration from .gitlab-ci.yml and other configuration if relevant (e.g. docker-compose.yml). Alternatively, create a public GitLab.com example project that provides all necessary files to reproduce the question.

echo -e "machine git.domain.cn\nlogin gitlab-ci-token\npassword ${CI_JOB_TOKEN}" > ~/.netrc
git config --global url."http://git.domain.cn/".insteadOf "git@git.domain.cn:"
git clone http://git.domain.cn/groupA/projectB.git script.

Versions

Please select whether options apply, and add the version information.

  • Self-managed
  • GitLab.com SaaS
  • Dedicated
  • Self-hosted Runners

Versions

  • GitLab (Web: /help or self-managed system information sudo gitlab-rake gitlab:env:info): v15.9.4
  • GitLab Runner, if self-hosted (Web /admin/runners or CLI gitlab-runner --version): v15.10.0,Git version:456e3482

Helpful resources

  1. Check the FAQ for helpful documentation, issues/bugs/feature proposals, and troubleshooting tips.
  2. Before opening a new topic, make sure to search for keywords in the forum search
  3. Check the GitLab and GitLab Runner projects for existing issues. If you encounter a bug, please create a bug report issue.
  4. Review existing troubleshooting docs.

Thanks for taking the time to be thorough in your request, it really helps! :blush:

Looking at the documentation, I’d suggest trying

git clone http://gitlab-ci-token:${CI_JOB_TOKEN}@git.domain.cn/groupA/projectB.git