【问题标题】:Jenkins does not detect GIT credentials from Windows Credential managerJenkins 没有从 Windows 凭据管理器中检测到 GIT 凭据
【发布时间】:2015-02-06 13:02:06
【问题描述】:

我有 2 个 GIT 存储库副本,我们称它们为 “origin”“backup”。我想要实现的是以下。 我的团队不断将他们的更改推送和同步到 "origin",但是我想确保我在不同的地理位置拥有一份 "origin" 副本作为副本,以防万一发生火灾,摧毁我办公室的一切。为了实现这一点,我在云上保留了我的 git 存储库的相同副本。

现在结合使用 Jenkins 和 Windows 批处理脚本,我正在尝试找出一种可以使这些存储库保持同步的方法。批处理脚本将负责实际的同步操作,Jenkins 将确保同步操作定期运行。复制的副本被命名为“backup”(您可能已经猜到了)。

问题是当我直接从命令提示符运行批处理脚本时,它会完全按照我的意愿执行;但是当我尝试通过 Jenkins 作业执行批处理脚本时,它一直在等待 "backup" 存储库的用户名和密码。 "backup" 存储库的凭据已存储在 Windows 凭据管理器中,并且批处理脚本在直接执行时能够使用凭据,但不知何故,当我尝试通过 Jenkins 执行它时,情况并非如此.

我尝试过谷歌搜索,搜索所以甚至做了很多搜索,看看我是否可以在 jenkins 论坛中找到一些东西,但到目前为止我还没有找到任何有用的东西。

我不确定这是否有用,但下面是我的批处理脚本供参考。

@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

这是我从 Windows 命令提示符看到的 GIT 配置。(我已将 user.name 和 user.email 替换为虚拟值)

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

这是我从 Jenkins 运行 (git config -l) 时得到的 GIT 配置

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

不用说,非常感谢任何帮助。

干杯。

【问题讨论】:

  • 你的 git 配置如何(git config -l)?直接跑和通过jenkins跑有区别吗?
  • 另外,无论如何,wincred 用户都不是特定的 - 所以你确定你对 jenkins 和当你直接运行它时使用相同的用户吗?
  • wincred用户在使用jenkins和直接运行时是一样的。
  • 我不知道如何检查 jenkins 的 git config,如果你告诉我怎么做,我可以检查并在此处发布。
  • @parth6 在services.msc(登录为列)中,Jenkins 服务是在“本地系统”下运行还是使用您的 Windows 帐户?它需要使用您的 Windows 帐户运行才能访问您保存的凭据。

标签: windows git batch-file jenkins credential-manager


【解决方案1】:

终于找到了解决办法。感谢David Ruhmann。 David 在他对问题的评论中提到的解决方案是转到 Windows 服务管理器并从 “本地系统” 更改 “Log On As” 列的值到您用于从命令提示符运行批处理脚本的 Windows 帐户。在我的例子中,由于 windows 的登录用户被称为 "BOB",将 Local System 值更改为 BOB 并指定该用户的登录密码在服务管理器中成功了。

还有一点要记住的是;要使更改生效,您必须重新启动 Jenkins 服务。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-15
    • 2021-03-01
    相关资源
    最近更新 更多