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

来源:互联网 发布:sql union关联 编辑:程序博客网 时间:2024/05/17 22:03

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

Started by user lhyBuilding in workspace /usr/share/tomcat8/.jenkins/workspace/zxpm > git rev-parse --is-inside-work-tree # timeout=10Fetching changes from the remote Git repository > git config remote.origin.url git@192.168.1.2:web/zxpm.git # timeout=10Fetching upstream changes from git@192.168.1.2:web/zxpm.git > git --version # timeout=10using 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.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:604)    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)    at hudson.model.AbstractBuild$AbstractBuildExecution.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 rightsand 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 moreERROR: nullFinished: 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,保存项目再次构建就好了。

0 0