0

I am trying to run a script with GitPython, but it seems to only fail when I run from inside the Jenkins automation environment. The error that it gives isn't very helpful (and I haven't been able to find a solution for it in my searching), so I'm hoping someone here can help.

Here's some data for my setup.

  • Git version: 2.45.2
  • python version: 3.12.4 (in a virtual environment)
  • GitPython module: 3.1.43

Error encountered (proprietary pathnames and other secrets removed):

Traceback (most recent call last):
  File "/path/to/auth_tester.py", line 5, in <module>
    repository.remote().pull()
  File "/path/to/pyenv/lib/python3.12/site-packages/git/remote.py", line 1123, in pull
    res = self._get_fetch_info_from_stderr(proc, progress, kill_after_timeout=kill_after_timeout)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/pyenv/lib/python3.12/site-packages/git/remote.py", line 895, in _get_fetch_info_from_stderr
    proc.wait(stderr=stderr_text)
  File "/path/to/pyenv/lib/python3.12/site-packages/git/cmd.py", line 834, in wait
    raise GitCommandError(remove_password_if_present(self.args), status, errstr)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(1)
  cmdline: git pull -v -- origin

Sample of the code that causes it (secrets also removed):

import os
from git import Repo

repository = Repo(".")
repository.remote().pull()

Is there an environment variable that might be missing from the Jenkins run, that would be included when I run it locally?

4
  • 2
    Does git pull -v -- origin work if you run it manually? Do you need authorization to pull from the remote repository? Remember, Jenkins is (probably) running as a different user than you. Commented Nov 12, 2024 at 3:48
  • 1
    I can run it on my own machine just fine. I can also remote into the Jenkins machine and run it there without issue. Commented Nov 12, 2024 at 8:12
  • 1
    Is the repository initially checked out by jenkins ? If yes, jenkins typically makes the initial checkout with detached head and i'd guess doing a git pull on detached head would fail because same commit can be in multiple branches. Another one is what transport should git use ? Commented Nov 12, 2024 at 9:04
  • > Is the repository initially checked out by jenkins ? It is, by I also ran another command to do "another" checkout, solving the detached head issue. > Another one is what transport should git use ? I used SSH (and deploy key) for a while, but also tried HTTPS (and a Personal Token) - both transports yielded the same error. Commented Nov 12, 2024 at 18:27

0

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.