GitLab CI:"权限被拒绝"当拉私人作曲家包

时间:2017-06-08 20:10:01

标签: gitlab-ci

我尝试使用GitLab设置CI,但我收到了这个构建错误:

  [RuntimeException]         

  Failed to execute git clone --no-checkout 'git@***.git' '/builds/***' && cd '/builds/***' && git remote add composer 'git@***.git' && git fetch composer  
  Cloning into '/builds/***'...       

  Permission denied, please try again. 

  Permission denied, please try again.                                                                                 
  Permission denied (publickey,password).                                                                            
  fatal: Could not read from remote repository.                                                                        
  Please make sure you have the correct access rights                                                                       
  and the repository exists.   

我的composer.json看起来像这样:

{
    "repositories": [
        {
            "type": "git",
            "url": "git@***.git"
        }],
}

这显然与ssh密钥对有关,但我不知道在哪里存储私钥/公钥。

1 个答案:

答案 0 :(得分:2)

我刚刚根据https://docs.gitlab.com/ee/ci/ssh_keys/README.htmlhttps://gitlab.com/gitlab-examples/ssh-private-key/blob/master/.gitlab-ci.yml上的示例为此实施了解决方案。

你基本上需要

  • 设置SSH代理(特别是在使用docker时)
  • 添加私有SSH密钥(最好是存储在GitLab中的变量,因为不应该签入凭据)

示例,如果链接被移动:

before_script:
  # install ssh-agent
  - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'

  # run ssh-agent
  - eval $(ssh-agent -s)

  # add ssh key stored in SSH_PRIVATE_KEY variable to the agent store
  - ssh-add <(echo "$SSH_PRIVATE_KEY")

  # Set up project.
  - composer install