- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Docker 容器中工作 git --version
2.20.1,基本镜像是 Debian 10。我想使用 GIT_ASKPASS
通过 HTTPS 克隆一个 git 存储库。甚至更好的配置属性 core.askpass
.这是我尝试过的:
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"
'
最初我是在 Jenkins 中运行它,但我发现我能够在一个简单的 docker 容器中重现同样的问题。 $JENKINS_CREDENTIALS_USR
和 $JENKINS_CREDENTIALS_PSW
定义如下:
JENKINS_CREDENTIALS_USR=myuser
JENKINS_CREDENTIALS_PSW=mypass
export JENKINS_CREDENTIALS_USR
export JENKINS_CREDENTIALS_PSW
我没有设置任何全局配置属性。 ~/.git-credentials
不存在。错误是:
fatal: Authentication failed for 'https://myserver.com/git/project.git/'
它通过在 HTTPS url 中指定用户名来工作,就像这样
git clone https://jenkins@myserver.com/git/project.git .
并且只在 GIT_ASKPASS
指向的脚本中打印密码,所以我想知道为什么如果没有 url 中的用户名它就不能工作。 documentation明确地说
If the
GIT_ASKPASS
environment 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.
因为当我尝试克隆时,我被要求同时输入用户名和密码,原来的GIT_ASKPASS
有什么问题?脚本?
最佳答案
我找到了解决方案 here .所有学分归于@AlexeyPelykh,我刚刚改编了他的剧本。
当尝试 git clone
时,我们的 shell 脚本会为每个提示行调用一次,基本上:
$GIT_ASKPASS "Username for ..."
$GIT_ASKPASS "Password for ..."
我的原始脚本中的问题是它返回的用户名和密码与我要求的内容无关。这也是为什么在第二种情况下(使用 URL 中指定的用户名)它起作用的原因,事实上我只需要密码并且它只返回密码。
这就是我如何更改我的原始脚本以使其与 GIT_ASKPASS
一起工作:
GIT_ASKPASS=$(mktemp) && chmod a+rx $GIT_ASKPASS && export GIT_ASKPASS
cat > $GIT_ASKPASS <<< '#!/bin/bash
case "$1" in
Username*) exec echo "$JENKINS_CREDENTIALS_USR" ;;
Password*) exec echo "$JENKINS_CREDENTIALS_PSW" ;;
esac
'
如果你想使用配置变量core.askPass
,用这些替换前两行:
git_askPass_script=$(mktemp) && chmod a+rx $git_askPass_script
cat > $git_askPass_script <<< '#!/bin/bash
并设置配置变量:
git config --global core.askPass "$git_askPass_script"
甚至更好
git -c core.askPass="$git_askPass_script" clone ...
关于bash - 带有用户和密码的 GIT_ASKPASS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68344358/
我在 Docker 容器中工作 git --version 2.20.1,基本镜像是 Debian 10。我想使用 GIT_ASKPASS 通过 HTTPS 克隆一个 git 存储库。甚至更好的配置属
我已经在 Jenkins 中为 bitbucket 设置了一些凭据,并仔细检查了凭据设置(例如手动登录),但是当我在 Jenkins 中尝试它时,它只会永远旋转并给出以下输出: > git con
我正在尝试通过 GIT_ASKPASS 向 git 提供密码,如下所示: export PASSWORD= export GIT_ASKPASS="/usr/bin/echo $PASSWORD" g
我是一名优秀的程序员,十分优秀!