下面是我的python腳本,注意這是為了測驗。
from types import StringType
from os.path import isabs
from os import system, popen, getenv
from glob import glob
cmd = "ssh-add -l"
returned_value = system(cmd) # returns the exit code in unix
print('returned value:', returned_value)
cmd = "git clone [email protected]:XXXXXXXXXX/python_git_test.git"
returned_value = system(cmd) # returns the exit code in unix
print('returned value:', returned_value)
當我從 CMD 運行它時
C:\Users\jenkins\Desktop>python test.py
3072 SHA256:dl91g2BDUmEVpRqqBjJ8oXeHsEKYueW LpmwCcGkd7I jenkins@cibuild1 (RSA)
3072 SHA256:i5kOlssdnL1g4RzB65bOira 4Y7LcSngp4sLCPb8aXI jenkins@CIBUILD3 (RSA)
('returned value:', 0)
Cloning into 'python_git_test'...
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
('returned value:', 128)
當我從 gitbash 運行它時
$ python test.py
3072 SHA256:dl91g2BDUmEVpRqqBjJ8oXeHsEKYueW LpmwCcGkd7I jenkins@cibuild1 (RSA)
Cloning into 'python_git_test'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
('returned value:', 0)
('returned value:', 0)
我有幾個問題,為什么當 gitbash 和 cmd 都在 ssh-agent 中加載了正確的密鑰時,我在 CMD 上收到錯誤訊息?
其次,這是一個更大的 Jenkins 構建問題的一小段。所以一般來說詹金斯是呼叫git updater python檔案的那個,我一直得到拒絕訪問的公鑰。有誰知道詹金斯會嘗試使用什么終端?我假設CMD?
uj5u.com熱心網友回復:
先嘗試設定set "GIT_SSH_COMMAND=ssh -Tv",然后python test.py在 CMD 中設定。
您將確切地看到 Git 使用什么作為 SSH 密鑰,以了解它為什么不訪問遠程存盤庫。
您可以在git bash會話中執行相同操作(將繼承 CMD 中設定的環境變數)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/442172.html
下一篇:僅對其中一種工具應用質量門
