2017-10-08 41 views
0

我想澄清:詹金斯的Git標籤/按鍵錯誤

  • 詹金斯主節點和工作節點如何使用Git溝通
  • 兩個節點如何使用證書和SSH插件使用Git來驗證
  • 時使用憑據插件vs SSHAgent插件

現在,我認爲主節點存儲所有憑證,然後將這些憑證傳遞給工作代理。這讓我相信只有一個節點 - 主節點 - 應該有git的ssh密鑰。

到目前爲止,這似乎是真實的,因爲在master上觸發構建時,即使沒有在worker代理上配置ssh密鑰,worker節點也能夠運行git clone和git init。

Started by user deploy-user 
Replayed #23 
18:01:03 Connecting to https://api.github.com using deploy-user/****** (username-with-password) 
Obtained Jenkinsfile from a12ea59545db96fc8681dbdd5d44923108c01b40 
[Pipeline] node 
Running on nodejs in /home/server/jenkins/workspace/K-Front_feature-jenkinsfile-KHCSHNIRHLZUOTSCIQPWI7 
[Pipeline] { 
[Pipeline] stage 
[Pipeline] { (Declarative: Checkout SCM) 
[Pipeline] checkout 
Cloning the remote Git repository 
Cloning with configured refspecs honoured and without tags 
Cloning repository https://github.com/WaterBottleInce/Frontend.git 
> git init /home/server/jenkins/workspace/K-Front_feature-jenkinsfile-KHCSHNIRHLZUOTSCIQPWI7 # timeout=10 
Fetching upstream changes from https://github.com/WaterBottleInce/Frontend.git 
> git --version # timeout=10 
using GIT_ASKPASS to set credentials username-with-password 
> git fetch --no-tags --progress https://github.com/WaterBottleInce/Frontend.git +refs/heads/feature-jenkinsfile:refs/remotes/origin/feature-jenkinsfile 
> git config remote.origin.url https://github.com/WaterBottleInce/Frontend.git # timeout=10 
> git config --add remote.origin.fetch +refs/heads/feature-jenkinsfile:refs/remotes/origin/feature-jenkinsfile # timeout=10 
> git config remote.origin.url https://github.com/WaterBottleInce/Frontend.git # timeout=10 
Fetching without tags 
Fetching upstream changes from https://github.com/WaterBottleInce/Frontend.git 
using GIT_ASKPASS to set credentials username-with-password 
> git fetch --no-tags --progress https://github.com/WaterBottleInce/Frontend.git +refs/heads/feature-jenkinsfile:refs/remotes/origin/feature-jenkinsfile 
Checking out Revision a12ea59545db96fc8681dbdd5d44923108c01b40 (feature-jenkinsfile) 
> git config core.sparsecheckout # timeout=10 
> git checkout -f a12ea59545db96fc8681dbdd5d44923108c01b40 
Commit message: "removes error in customworkspace" 
> git rev-list a12ea59545db96fc8681dbdd5d44923108c01b40 # timeout=10 

那麼爲什麼做這一步:

steps{ 
    sh('git remote -v') 
    sh('git show-ref') 
    sh('git tag -a $BRANCH_NAME.$BUILD_NUMBER -m "git sha is $GIT_COMMIT"') 
    sh('git push origin HEAD:development --tags') 
} 

導致此錯誤:

[Pipeline] } 
[Pipeline] // withEnv 
[Pipeline] } 
[Pipeline] // stage 
[Pipeline] stage 
[Pipeline] { (Deploy-Staging) 
[Pipeline] tool 
[Pipeline] envVarsForTool 
[Pipeline] withEnv 
[Pipeline] { 
[Pipeline] sh 
[K-Front_feature-jenkinsfile-KHCSHNIRHLZUOTSCIQPWI7] Running shell script 
+ git remote -v 
origin https://github.com/WaterBottleInc/Reactjs-Front.git (fetch) 
origin https://github.com/WaterBottleInc/Reactjs.git (push) 
[Pipeline] sh 
[K-Front_feature-jenkinsfile-KHCSHNIRHLZUOTSCIQPWI7] Running shell script 
+ git show-ref 
a12ea59545db96fc8681dbdd5d44923108c01b40 refs/remotes/origin/feature-jenkinsfile 
[Pipeline] sh 
[K-Front_feature-jenkinsfile-KHCSHNIRHLZUOTSCIQPWI7] Running shell script 
+ git tag -a feature-jenkinsfile.24 -m git sha is a12ea59545db96fc8681dbdd5d44923108c01b40 
[Pipeline] sh 
[K-Front_feature-jenkinsfile-KHCSHNIRHLZUOTSCIQPWI7] Running shell script 
+ git push origin HEAD:development --tags 
fatal: could not read Username for 'https://github.com': No such device or address 
[Pipeline] } 
[Pipeline] // withEnv 
[Pipeline] } 
[Pipeline] // stage 
[Pipeline] stage 
[Pipeline] { (Declarative: Post Actions) 
[Pipeline] deleteDir 
[Pipeline] } 
[Pipeline] // stage 
[Pipeline] } 
[Pipeline] // withEnv 
[Pipeline] } 
[Pipeline] // withEnv 
[Pipeline] } 
[Pipeline] // withEnv 
[Pipeline] } 
[Pipeline] // node 
[Pipeline] End of Pipeline 

這條線從錯誤中打印出上面:

fatal: could not read Username for 'https://github.com': No such device or address 

完全把我拋下,因爲我不知道我在哪裏t正在尋找用戶名。

有人可以幫我嗎?謝謝。

回答

1

此:

steps{ 
    sh('git remote -v') 
    sh('git show-ref') 
    sh('git tag -a $BRANCH_NAME.$BUILD_NUMBER -m "git sha is $GIT_COMMIT"') 
    sh('git push origin HEAD:development --tags') 
} 

失敗,因爲在主節點中定義的憑據不會自動綁定/傳遞到構建工作。我們需要suite of Credentials Plugins。一旦安裝完成,我們就利用withCredentials() function來傳遞驗證/與git通信所需的證書。

如需進一步說明,請在jenkins-user forum上閱讀本文