我通过SSH协议远程运行git命令,因为服务器不接受HTTPS。我通过bash脚本运行它,并希望我可以传入用户名和密码作为变量。使用用户名和密码的SSH git命令
更具体地说,我做仓库的迁移,并通过詹金斯工作运行
git remote add origin ssh://${username}:${password}@server.com/repo.git
我运行该脚本,我不能够很容易地提示输入密码时,我有问题。将密钥复制到远程服务器是我的最佳选择吗?
我通过SSH协议远程运行git命令,因为服务器不接受HTTPS。我通过bash脚本运行它,并希望我可以传入用户名和密码作为变量。使用用户名和密码的SSH git命令
更具体地说,我做仓库的迁移,并通过詹金斯工作运行
git remote add origin ssh://${username}:${password}@server.com/repo.git
我运行该脚本,我不能够很容易地提示输入密码时,我有问题。将密钥复制到远程服务器是我的最佳选择吗?
另一种方法是使用凭证绑定插件。这个插件允许将凭证绑定到环境变量,以便从其他构建步骤中使用。
你总是可以只登录到远程复选框,并添加Github上凭据手动
干杯
假设你正在使用的是最新的Git版本,您可以使用GIT_SSH_COMMAND
环境变量:
GIT_SSH, GIT_SSH_COMMAND If either of these environment variables is set then git fetch and git push will use the specified command instead of ssh when they need to connect to a remote system. The command will be given exactly two or four arguments: the [email protected] (or just host) from the URL and the shell command to execute on that remote system, optionally preceded by -p (literally) and the port from the URL when it specifies something other than the default SSH port. $GIT_SSH_COMMAND takes precedence over $GIT_SSH, and is interpreted by the shell, which allows additional arguments to be included. $GIT_SSH on the other hand must be just the path to a program (which can be a wrapper shell script, if additional arguments are needed). Usually it is easier to configure any desired options through your personal .ssh/config file. Please consult your ssh documentation for further details.
因此,你叫git
之前,你可以简单:
export GIT_SSH_COMMAND='ssh -i /path/to/key'
如果你不能使用SSH密钥,就可以使用该Jenkins Credential Binding plugin。
凭证绑定如何与GIT_SSH_COMMAND协同工作?或者你可以在Jenkins Credentail中用你的ssh密钥绑定一个git命令吗? – red888
恩,我建议你重新阅读这个问题。 OP明确表示https不被允许。 – eis
删除了我的第一个选项。感谢您的支持 –