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
2
  • side note : you should be able to call git subcomannds as though they were methods of the repo.git object (link to docs) e.g : repo.git.add('--all', '--', ':!build-infrastructure'), repo.git.commit('-m', generic_commit_message), repo.git.push(), etc ... Commented Nov 3, 2020 at 13:12
  • @LeGEC good point, this is much more straight forward Commented Nov 3, 2020 at 20:48

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for you help, the solution was to allow connection persistence in the checkout-step.
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

2 Comments

@CeceDong-MSFT I will do this, it's just possible tomorrow.
@CeceDong-MSFT Were there any changes in behavior? Last week it still worked without checkout ....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.