BendEg
BendEg

Reputation: 21088

Using GitPython in Azure DevOps pipelines causes 'git: 'credential-manager-core' is not a git command

When we use GitPython in Azure DevOps and try to push to a repository, the following message occurs (same repository as cloned by the pipeline):

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

Infrastructure: GitHub, Windows build machine (latest)

Since our working-directory is the currently cloned repository, we initialize the repository like this:

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')

So pushing the changes should work with the same credentials, as Azure DevOps used for pulling. Am I missing something?

SOLUTION

The solution is to override the checkout step in the pipeline: https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema#checkout

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

Upvotes: 1

Views: 1269

Answers (2)

BendEg
BendEg

Reputation: 21088

SOLUTION

The solution is to override the checkout step in the pipeline: https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema#checkout

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

Upvotes: 1

LeGEC
LeGEC

Reputation: 51780

Check what url is used for the remote is registered : repo.git.remote('-v')

It could be that the url is one that wouldn't need credentials when pulling.


I, for one, don't know how the container (or process or whatever) that is started by Azure DevOps is created ; it could well be that the setup is done with one account, then the commands are executed with a different one (or within a container, or ... )

Check how the config is set up : repo.git.config('-l'), if target executable is available from the $PATH ...


You may need to add some step in the setup part of your pipeline (e.g: install said credential manager).

Upvotes: 1

Related Questions