简体   繁体   中英

Jenkins does not detect GIT credentials from Windows Credential manager

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.

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.

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