简体   繁体   English

git clone 在 jenkins 中返回权限问题

[英]git clone returns permission issue in jenkins

I have a jenkins and I clone a repo using jenkins configuration.我有一个 jenkins,我使用 jenkins 配置克隆了一个 repo。 Then in that repo I have an ansible task which clones another repo:然后在那个仓库中,我有一个克隆另一个仓库的 ansible 任务:

- name: Mock Server
  vars:
    mock_server: "{{ base_build_path }}/uds-mock-server"
  git:
    repo: 'git@github.ibm.com:xxxxx/mock-server.git'
    dest: "{{ mock_server }}"
    clone: yes
    recursive: yes
    version: master
    track_submodules: yes

Now the problem is since the code running inside the jenkins does not have access to the repo I get:现在的问题是因为在 jenkins 中运行的代码无法访问我得到的 repo:

"Permission denied (publickey).", "fatal: Could not read from remote repository.", "", "Please make sure you have the correct access rights", "and the repository exists."], "stdout": "", "stdout_lines": []}

So is there anyway I can add private key in jenkins in configuration then it will use that key when it clones the repo?那么无论如何我可以在配置中在 jenkins 中添加私钥,然后它会在克隆 repo 时使用该密钥?

The key needs to be available for the remote_user on the target server running the task.密钥需要对运行任务的目标服务器上的remote_user可用。 By default it will read the default ssh keys available in ~/.ssh (eg id_rsa if you created an rsa one).默认情况下,它将读取~/.ssh可用的默认 ssh 密钥(例如,如果您创建了 rsa 密钥,则为id_rsa )。

If the key is not in the default location/name, thegit module has a key_file parameter you can use to point to the correct location.如果密钥不在默认位置/名称中,则git模块有一个key_file参数,您可以使用它来指向正确的位置。

You can either copy that key prior to running your playbook or in a task just before running git.您可以在运行 playbook 之前或在运行 git 之前的任务中复制该密钥。

If you want to control everything from Jenkins, you could add the key content as a "secret file" credential in Jenkins, bind that credential to a var (which will contain the path to the secret temporary file), copy that file to the target server and use that uploaded file as the key (default or custom) in your ansible git task.如果您想控制 Jenkins 的所有内容,您可以在 Jenkins 中添加密钥内容作为“秘密文件”凭证,将该凭证绑定到一个 var(它将包含秘密临时文件的路径),将该文件复制到目标服务器并使用该上传的文件作为您的 ansible git任务中的密钥(默认或自定义)。

确保 (Settings > Repository > Deploy Keys) 下的 Repo's Deployed Key 已启用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM