1

I have 2 copies of GIT repositories let's call them "origin" and "backup". What I want to achieve is the following. My team constantly keeps pushing and syncing their changes to "origin", however I want to ensure that I have a copy of "origin" in a different geographical location which will serve as a duplicate copy just in case a fire was to break out destroying everything in my office. In order to achieve this I have kept an identical copy of my git repo hosted on the cloud.

Now using a combination of Jenkins and a windows batch script I am trying to figure out a way where I can keep these repositories in sync. The batch script will be responsible for the actual sync operation and Jenkins will ensure that the sync operation runs periodically. The duplicate copy is named "backup" (as you may have already guessed).

The problem is when I run the batch script from the command prompt directly it executes exactly as I want it to; But when I try to execute the batch script via Jenkins job, it keeps waiting for username and password of the "backup" repository. The credentials for "backup" repository are already stored in Windows Credential manager and the batch script is able to use the credentials when executed directly, but somehow that is not the case when I try to execute it via Jenkins.

I have tried googling, searching SO even did a lot of search to see if I could find something in jenkins forums, but so far I haven't found anything helpful.

I am not sure if this will be of any use, but below is my batch script for reference.

@echo OFF

pushd K:

pushd "K:\my-git-workspace\mygit-repo"

echo Pulling "master" from origin
git pull origin master

echo Pulling "master" from backup
git pull backup master

echo Pushing "master" to backup
git push backup master

echo Pushing "master" to origin
git push origin master

echo Pulling all tags from origin
git pull --tags origin

echo Pulling all tags from backup
git pull --tags origin

echo Pushing all tags to backup
git  push --tags backup

echo Pushing all tags to origin
git push --tags origin

popd

Here is my GIT configuration that I see from the windows command prompt.(I have replaced the user.name and user.email with dummy values)

core.symlinks=false
core.autocrlf=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=/bin/curl-ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
diff.astextplain.textconv=astextplain
rebase.autosquash=true
user.email=myemail@domain.com
user.name=My Name
credential.helper=wincred

Here is the GIT configuration that I get when run (git config -l) from Jenkins

core.symlinks=false
core.autocrlf=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
pack.packsizelimit=2g
help.format=html
http.sslcainfo=/bin/curl-ca-bundle.crt
sendemail.smtpserver=/bin/msmtp.exe
diff.astextplain.textconv=astextplain
rebase.autosquash=true
user.email=myemail@domain.com
user.name=My Name
credential.helper=wincred
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
core.hidedotfiles=dotGitOnly
remote.origin.url=//networkrepo/git/repo
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
remote.backup.url=http://cloud-hosted-git-repo/repo.git
remote.backup.fetch=+refs/heads/*:refs/remotes/backup/*
gui.wmstate=zoomed
gui.geometry=584x210+321+316 304 192
credential.helper=store
user.email=myemail@domain.com
user.name=My Name

Goes without saying, any help is greatly appreciated.

Cheers.

Parth
  • 367
  • 6
  • 18
  • how's your git configuration (`git config -l`)? is there difference between running directly and running through jenkins? – eis Feb 06 '15 at 13:07
  • also, isn't wincred user specific anyway - so are you sure you are using same user for both jenkins and when you run it directly? – eis Feb 06 '15 at 13:08
  • The wincred user is same while using jenkins and while running it directly. – Parth Feb 06 '15 at 13:09
  • I don't know how to check git config for jenkins, I can check that and post it here, if you tell me how. – Parth Feb 06 '15 at 13:13
  • just put `git config -l` in a .bat file and execute that as a jenkins job, for example – eis Feb 06 '15 at 13:14
  • @eis I have updated the question to include both configurations. There are obvious differences, I don't understand why? And how do I bridge the configuration gap by modifying GIT configuration for jenkins? – Parth Feb 06 '15 at 13:21
  • I have updated my GIT configuration in jenkins to include the missing parameters of user.name, user.email and credential.helper; But the problem is still intact. Any other ideas? – Parth Feb 06 '15 at 14:02
  • 4
    @parth6 In `services.msc` (Log On As column) is the Jenkins service running under "Local System" or is it using your Windows account? It needs to be running using your Windows account to access your Saved Credentials. – David Ruhmann Feb 06 '15 at 16:30
  • @parth6 if you have added those, re-run `git config -l` and update the question – eis Feb 07 '15 at 15:39

1 Answers1

7

Finally found out the solution. Thanks to David Ruhmann. The solutions as David has mentioned in his comment to the question, is to go to windows service manager and change the value for "Log On As" column from "Local System" to the Windows Account that you are using to run the batch script from command prompt. In my case since the login user for windows was called "BOB", changing Local System value to BOB and specifying the login password for this user in service manager did the trick.

One more thing to remember would be; For the change to take effect, you will have to restart the Jenkins service.

Community
  • 1
  • 1
Parth
  • 367
  • 6
  • 18