【发布时间】: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