在Azure DevOps管道中使用GitPython会导致'git:'credential-manager-core'不是git命令

时间:2020-11-03 10:38:49

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

当我们在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

2 个答案:

答案 0 :(得分:1)

检查用于遥控器的URL已注册:repo.git.remote('-v')

可能是该网址是在提取时不需要凭据的网址。


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

检查配置如何设置:repo.git.config('-l'),如果可以从$PATH中获得目标可执行文件...


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

答案 1 :(得分:0)

解决方案

解决方案是覆盖管道中的结帐步骤: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