首页 > 解决方案 > 詹金斯共享库:权限被拒绝(公钥)

问题描述

我尝试在jenkins中动态加载一个共享库,托管在github上,如下所示

library identifier: 'custom-lib@master', retriever: modernSCM(
  [$class: 'GitSCMSource',
   remote: 'ssh://git@github.com:papanito/jenkins-pipeline-helper.git',
   credentialsId: 'git'])

但是,这失败并出现以下错误

hudson.plugins.git.GitException: Command "git ls-remote -h -t git@github.com:papanito/jenkins-pipeline-helper.git" returned status code 128:
stdout: 
stderr: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights

我正在使用的凭据具有有效的私钥,并且当我通过 Jenkins 设置使用该库时可以正常工作。但是,在管道中动态加载它不起作用。任何线索为什么?

标签: jenkinsgithubjenkins-pipeline

解决方案


只需将您的密钥移动到文件夹中并授予文件夹 chmod 600 级访问权限。然后从该文件夹中添加密钥。SSH-add 应该适合你。


推荐阅读