【问题标题】:Using GitPython in Azure DevOps pipelines causes 'git: 'credential-manager-core' is not a git command在 Azure DevOps 管道中使用 GitPython 会导致 'git: 'credential-manager-core' 不是 git 命令
【发布时间】:2020-11-03 10:38:49
【问题描述】:

当我们在 Azure DevOps 中使用 GitPython 并尝试推送到存储库时,会出现以下消息(与管道克隆的存储库相同):

  stderr: 'git: 'credential-manager-core' is not a git command. See 'git --help'.

基础架构:GitHub、Windows 构建机器(最新)

由于我们的工作目录是当前克隆的存储库,我们像这样初始化存储库:

import git
repo = git.Repo('.')
# Do some stuff
repo.git.execute('git add --all -- ":!build-infrastructure"')
repo.git.execute(f'git commit -m "{generic_commit_message}"')
repo.git.execute('git push')

因此,推送更改应使用与用于拉取的 Azure DevOps 相同的凭据。我错过了什么吗?

解决方案

解决方案是覆盖管道中的checkout 步骤:https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema#checkout

steps:
  - checkout: self
    submodules: true
    persistCredentials: true

【问题讨论】:

  • 旁注:您应该能够调用 git 子命令,就好像它们是 repo.git 对象 (link to docs) 的方法,例如:repo.git.add('--all', '--', ':!build-infrastructure')repo.git.commit('-m', generic_commit_message)repo.git.push() 等...
  • @LeGEC 好点,这更直接

标签: git azure-devops gitpython azure-devops-pipelines git-credential-manager


【解决方案1】:

检查远程注册使用的网址:repo.git.remote('-v')

可能是 url 在拉取时不需要凭据。


一方面,我不知道由 Azure DevOps 启动的容器(或进程或其他)是如何创建的;很可能是使用一个帐户完成设置,然后使用另一个帐户执行命令(或在容器内,或...)

检查配置的设置方式:repo.git.config('-l'),如果目标可执行文件可从$PATH...


您可能需要在管道的设置部分添加一些步骤(例如:安装上述凭据管理器)。

【讨论】:

  • 感谢您的帮助,解决方案是在结帐步骤中允许连接持久性。
【解决方案2】:

解决方案

解决方案是覆盖管道中的结帐步骤:https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema#checkout

steps:
  - checkout: self
    submodules: true
    persistCredentials: true

【讨论】:

  • 请尽可能Accept your reply as an Answer,这对阅读此主题的其他社区成员会有所帮助。
  • @CeceDong-MSFT 我会这样做,明天就有可能。
  • @CeceDong-MSFT 行为有什么变化吗?上周它在没有checkout ... 的情况下仍然有效。
猜你喜欢
  • 2022-07-06
  • 2021-11-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-23
  • 2023-03-20
  • 2018-10-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多