jenkins如何构build/克隆安装在Docker容器中的远程git仓库?

我有一个支持Docker容器的专用Synology NAS Cloud。 现在我计划一个私人构build和部署pipe道或类似的东西。

我做的第一步是:

  1. 在Synology上安装Git Server
  2. 初始化一些回购
  3. 克隆他们在我的MacBook上
  4. 通过ssh进行通信(commit,push,pull)

– >一切正常。

现在我已经在NAS上启动了一个Jenkins映像的Docker容器。 我想让Jenkins在NAS上(我在MacBook上克隆的同一个存储库)轮询我的远程存储库。 我还将所有远程存储库的“/ git”文件夹挂载到Jenkins Docker容器中。

所以我想将知识库URL添加到Jenkins作业中:
file:///git/firstRepo
—>但这不工作:(

 ERROR: Error fetching remote repo 'origin' hudson.plugins.git.GitException: Failed to fetch from file:///git/firstRepo at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:817) at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1084) at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1115) at hudson.scm.SCM.checkout(SCM.java:495) at hudson.model.AbstractProject.checkout(AbstractProject.java:1276) at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild. java:560) at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86) at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:485) at hudson.model.Run.execute(Run.java:1735) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:405) Caused by: hudson.plugins.git.GitException: Command "/usr/bin/git fetch --tags --progress file:///git/firstRepo +refs/heads/*:refs/remotes/origin/*" returned status code 128: stdout: stderr: fatal: '/git/firstRepo' does not appear to be a git repository 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:1924) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1643) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:71) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:352) at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:815) ... 11 more ERROR: Error fetching remote repo 'origin' Finished: FAILURE 

我testing通过docker shell将repo克隆到Jenkins工作区中
git clone file:///git/firstRepo
– >有效。 但在那里我用“root”login。

所以我的问题是:
Jenkins如何访问git文件夹? 这是访问权限的问题吗? jenkins显然不是“根”。 我必须“chown”git文件夹给我的Jenkins用户(我认为是“admin”)?

非常感谢!

首先,检查path:通常,这些回购(用于推送)是裸回购,这意味着他们的path应该是一个扩展名为.git的文件夹。

 .../git/firstRepo.git 

其次,用简单的构build步骤尝试一个简单的Jenkins作业(没有任何SCM设置)

 id -a ls -alrth /git ls -alrth /git/firstRepo ls -alrth /git/firstRepo.git 

这将向您显示与这些path相关的权限,并告诉您Jenkins(以id -a显示的用户身份执行)是否有权访问或不访问该path。