解决Jenkins+Gitlab出现的stderr: Permission denied权限问题

在使用Jenkins构建拉取Gitlab上的仓库时总是出现权限失败,无法访问的情况,如打印以下信息:

Started by user lhy
Building in workspace /usr/share/tomcat8/.jenkins/workspace/zxpm

git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
git config remote.origin.url git@192.168.1.2:web/zxpm.git # timeout=10
Fetching upstream changes from git@192.168.1.2:web/zxpm.git
git --version # timeout=10
using GIT_SSH to set credentials
git -c core.askpass=true fetch --tags --progress git@192.168.1.2:web/zxpm.git +refs/heads/:refs/remotes/origin/
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from git@192.168.1.2:web/zxpm.git
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:799)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1055)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1086)
at hudson.scm.SCM.checkout(SCM.java:485)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1269)
at hudson.model.AbstractBuildAbstractBuildExecution.defaultCheckout(AbstractBuild.java:604) at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86) at hudson.model.AbstractBuildAbstractBuildExecution.run(AbstractBuild.java:529)
at hudson.model.Run.execute(Run.java:1741)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:531)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:410)
Caused by: hudson.plugins.git.GitException: Command "git -c core.askpass=true fetch --tags --progress git@192.168.1.2:web/zxpm.git +refs/heads/:refs/remotes/origin/" returned status code 128:
stdout:
stderr: 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.

at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1740)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1476)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:63)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:314)
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:797)
... 11 more

ERROR: null
Finished: FAILURE

这个问题只需要细心点就可以了。配置Jenkins项目时,在源码管理中选择Git(前提是已安装好Git插件),填好仓库地址,认证点击Add,如图

在Kind中选择SSH Username with private key,下面的Private Key选择Enter directly直接输入在Gitlab部署了public key对应的private key即可。一般public key是在~/.ssh/id_rsa.pub,而private key是~/.ssh/id_rsa。
点击OK,保存项目再次构建就好了。


作者:风格lu
来源:CSDN
原文:https://blog.csdn.net/lusyoe/article/details/52782368
版权声明:本文为博主原创文章,转载请附上博文链接!

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,032评论 19 139
  • 近年来,由于开源项目、社区的活跃热度大增,进而引来持续集成(CI)系统的诞生,也越发的听到更多的人在说协同开发、敏...
    a6fc544968bb阅读 9,468评论 0 30
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,481评论 0 10
  • 我对视那双穿过寒夜的眼睛,冷冷的光变了炽热的得意。我分了神,黑衣人瞅紧机会,剑影纵横,划伤了我的左臂,我回防不及,...
    风雷余大鱼阅读 661评论 1 0
  • 5岁的小外甥女希希今年春节寒假期间有段时间住我家,于是我每天晚饭后散步就必须带上她,以给我爸妈休息一会。 ...
    蜂蜜乌龙茶阅读 406评论 0 0