繁体   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