简体   繁体   中英

how can a jenkins build/clone a remote git repo which is mounted into it's docker container?

I have a private Synology NAS Cloud which supports Docker containers. Now i plan a private build and deploy pipeline or something like this.

My first steps which are done:

  1. install Git Server on the Synology
  2. init some Repos
  3. clone them on my MacBook
  4. communicate over ssh (commit, push, pull)

--> all works fine.

Now i have started a Docker container on the NAS with a Jenkins image. i want the Jenkins to poll my remote repository on the NAS (same repository which i cloned on my MacBook). I also mounted the "/git" folder with all the remote repositories into the Jenkins Docker container.

So I want to add the repository URL to a Jenkins job:
file:///git/firstRepo
---> but that doesn't work :(


    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



I tested to clone the repo via docker shell into the Jenkins workspace with
git clone file:///git/firstRepo
-> that works. But there I am logged in with "root".


How can Jenkins access the git folder? Is it a problem with the access rights? Obviously the Jenkins is not the "root". Do i have to "chown" the git folder to my Jenkins user (which i think is "admin")?


First, check the path: usually, those repos (used for pushing) are bare repos, meaning their path should be a folder with a .git extension.

.../git/firstRepo.git

Second, try a simple Jenkins Job (without any SCM setting) with a simple build step

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

That will show you the rights associated with those paths, and tells you if Jenkins (executed as the user shown in id -a ) has the right or not to access that path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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