I am working in a Docker container with git --version 2.20.1, the base image is Debian 10. I would like to clone a git repository through HTTPS using GIT_ASKPASS or even better the configuration property core.askpass. Here is what I tried:
GIT_ASKPASS=$(mktemp) && chmod a+rx $GIT_ASKPASS && export GIT_ASKPASS
cat > $GIT_ASKPASS <<< '#!/bin/bash
exec printf "$JENKINS_CREDENTIALS_USR\n$JENKINS_CREDENTIALS_PSW\n"
'
Originally I was running it in Jenkins, but I saw that I am able to reproduce the same issue in a simple docker container. $JENKINS_CREDENTIALS_USR and $JENKINS_CREDENTIALS_PSW are defined like this:
JENKINS_CREDENTIALS_USR=myuser
JENKINS_CREDENTIALS_PSW=mypass
export JENKINS_CREDENTIALS_USR
export JENKINS_CREDENTIALS_PSW
I have not any global configuration property set. ~/.git-credentials does not exist. The error is:
fatal: Authentication failed for 'https://myserver.com/git/project.git/'
It works by specifying the username in the HTTPS url, like this
git clone https://jenkins@myserver.com/git/project.git .
and printing the password only in the script pointed by GIT_ASKPASS, so I am wondering why it does not work without the username in the url. The documentation clearly says that
If the
GIT_ASKPASSenvironment variable is set, the program specified by the variable is invoked. A suitable prompt is provided to the program on the command line, and the user's input is read from its standard output.
Because when I try to clone, I am asked for both username and password, what is wrong with the original GIT_ASKPASS script?