1

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
BendEg
  • 20,098
  • 17
  • 57
  • 131
  • side note : you should be able to call git subcomannds as though they were methods of the `repo.git` object ([link to docs](https://gitpython.readthedocs.io/en/stable/tutorial.html#using-git-directly)) e.g : `repo.git.add('--all', '--', ':!build-infrastructure')`, `repo.git.commit('-m', generic_commit_message)`, `repo.git.push()`, etc ... – LeGEC Nov 03 '20 at 13:12
  • @LeGEC good point, this is much more straight forward – BendEg Nov 03 '20 at 20:48

2 Answers2

1

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

LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • thanks for you help, the solution was to allow connection persistence in the checkout-step. – BendEg Nov 03 '20 at 21:16
1

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
BendEg
  • 20,098
  • 17
  • 57
  • 131
  • Please [Accept your reply as an Answer](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) once you can, this can be beneficial to other community members reading this thread. – Cece Dong - MSFT Nov 04 '20 at 03:13
  • @CeceDong-MSFT I will do this, it's just possible tomorrow. – BendEg Nov 04 '20 at 07:30
  • @CeceDong-MSFT Were there any changes in behavior? Last week it still worked without `checkout ...`. – BendEg Nov 04 '20 at 07:33