GitLab CI:拉私人作曲家包时“权限被拒绝”

最后发布: 2017-06-08 20:10:01


问题

我正在尝试使用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密钥对有关,但我不知道在哪里存储私钥/公钥。

}
gitlab-ci
回答

我只是实现了一个解决方案,基于https://docs.gitlab.com/ee/ci/ssh_keys/README.html和例子https://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 
}