簡體   English   中英

詹金斯 Git 標簽/推送錯誤

[英]Jenkins Git Tag/Push Error

我想澄清一下:

  • jenkins 主節點和工作節點如何與 git 通信
  • 兩個節點如何使用憑據和 ssh 插件通過 git 進行身份驗證
  • 何時使用 Credentials 插件與 SSHAgent 插件

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

到目前為止,這似乎是正確的,因為當在 master 上觸發構建時,即使在工作代理上沒有配置 ssh 密鑰,工作節點也能夠運行 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

完全讓我失望,因為我不知道它在哪里尋找用戶名。

有人可以幫我嗎? 謝謝。

這個:

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')
} 

失敗,因為主節點中定義的憑據不會自動綁定/傳遞到構建作業。

要綁定憑據,我們需要Credentials Plugins 套件 一旦安裝了這些,我們就會使用withCredentials() 函數來傳遞與 git 進行身份驗證/通信所需的憑據。

如果您需要更多說明,請閱讀jenkins-user 論壇上的這篇文章

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM