Azure DevOps Pipeline: ‘fatal: could not read Username for ‘https://mercury.tfs.siemens

Pipeline 功能:

代码存放 Azure TFS,使用 Azure DevOps Pipeline,通过调用本地 bat 文件,bat 调用 python 代码,对 TFS 代码库 repo 里的 lua 文件进行加密,并把加密后文件 push 回 repo.

Pipeline Yaml:

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
- master

pool: 'yourPoolName'

steps:
- task: BatchScript@1
  inputs:
    filename: ./TOOLS/desktop_standalone_tool/encrypt_all_lua_tool.bat

python 操作 git 时候,报 'fatal: could not read Username for 'https://mercury.tfs.siemens"

方法1:

vim .git/config 文件,在remote "origin"  url 中加入帐号密码,如图所示,格式为 https://username:password@git.dev.tencent.com/xxx/xxx.git

方法2:使用SSH

git 命令行SSH:

1.创建ssh key

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

代码参数含义:

-t 指定密钥类型,默认是rsa,可以省略。
-C 设置注释文字,比如邮箱。
-f 指定密钥文件存储文件名。

不使用-f指定文件名,下一步会提示让你输入文件名:

Generating public/private rsa key pair.
# Enter file in which to save the key (/c/Users/you/.ssh/id_rsa): [Press enter]

 若不输入直接按 enter,则使用默认文件名(强烈建议这么做!!!!),并在~/.ssh目录下生成id_rsa 和 id_rsa.pub 两个文件

然后会提示输入密码

Enter passphrase (empty for no passphrase): 
# Enter same passphrase again:

这个密码是每次 push 时需要输入的密码。同样地,也可以不输入密码,直接按回车跳过这个步骤,这样以后 push 的时候才能不用输密码

之后就会显示如下

Your identification has been saved in /c/Users/z003vyhd/.ssh/id_rsa
Your public key has been saved in /c/Users/z003vyhd/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:cdL+HHq8At6aDP9C/TkaCXw5UngfP9tUS15pToty/xU xiaolei.xu@siemens.com
The key's randomart image is:
+---[RSA 4096]----+
|                 |
|         o      .|
|        + = .  =o|
|       . B o oB =|
|        S.=.oooE.|
|        o+.Bo..=.|
|      .o o+.=...o|
|       +o.oo+.  o|
|        =+oo..  .|
+----[SHA256]-----+

 2、添加 ssh key 到 TFS

到key生成目录 ~/.ssh 下找到 id_rsa.pub 文件并用编辑器打开,复制里面的内容. Manage SSH keys, 添加。

3. be sure to configure the SSH agent to cache your passphrase so you don't have to enter it every time you connect

start-ssh-agent.cmd

4. 如果是 SSH URL 改变,要做更新 Use SSH key authentication

SSH URLs have changed, but old SSH URLs will continue to work. If you have already set up SSH, you should update your remote URLs to the new format:

  • Verify which remotes are using SSH by running git remote -v in your Git client.
  • Visit your repository on the web and select the Clone button in the upper right.
  • Select SSH and copy the new SSH URL.
  • In your Git client, run: git remote set-url <remote name, e.g. origin> <new SSH URL>. Alternatively, in Visual Studio, go to Repository Settings, and edit your remotes.
z003vyhd@md2vfekc MINGW64 /d/workspace/HW_CONFIG_CI (master)
$ git remote -v
origin  https://mercury.tfs.siemens.net/tfs/Botticelli/SINAMICS%20MV%20SEDS/_git/HW_CONFIG_CI (fetch)
origin  https://mercury.tfs.siemens.net/tfs/Botticelli/SINAMICS%20MV%20SEDS/_git/HW_CONFIG_CI (push)

z003vyhd@md2vfekc MINGW64 /d/workspace/HW_CONFIG_CI (master)
$ git remote set-url origin ssh://mercury.tfs.siemens.net:22/tfs/Botticelli/SINAMICS%20MV%20SEDS/_git/HW_CONFIG_CI

5. 测试

ssh -T git@ssh.dev.azure.com

 If everything is working correctly, you'll receive a response which says: remote: Shell access is not supported. If not, see the section on Questions and troubleshooting.

完成上述设置,可直接用 git 命令行进行push操作。如果用的是TortuiseGit,则需要进行如下设置:

TortuiseGit ssh设置:

TortoiseGit 使用扩展名为ppk的密钥,而不是 ssh-keygen 生成的rsa密钥。

也就是说使用 ssh-keygen  -t rsa  -C "username@email.com"产生的密钥,TortoiseGit 中不能用。

github/Azure TFS要用到 rsa 的密钥,使用TortoiseGit的putty key generator工具,将私钥转成 .ppk格式。(“putty key generator” 也可直接生成 rsa 密钥)

1、点击 “Load”, “C:\Users\xxx\.ssh” 下的生成的私钥,点击 Save private key  按钮保存为适用于TortoiseGit的私钥,扩展名为.ppk。

2、运行TortoiseGit开始菜单中的Pageant程序,在弹出的key管理列表中,点击add key,将第4步中保存的私钥(.ppk)文件加进来。

注:没有这一步,会导致每次push都要求密码。

3、回到项目目录下,右键——TortoiseGit——Settings——点击Remote,将第4步中保存的私钥(.ppk)文件加进来。

URL后面填的是 git仓库的 ssh地址。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值