Jenkins Git标签/推送错误

时间:2017-10-08 18:45:55

标签: git jenkins jenkins-pipeline

我想澄清一下:

  • jenkins主节点和工作节点如何与git进行通信
  • 两个节点如何使用凭据和ssh插件通过git
  • 进行身份验证
  • 何时使用Credentials插件与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

完全抛弃了我,因为我不知道它在哪里寻找用户名。

有人可以帮帮我吗?谢谢。

1 个答案:

答案 0 :(得分: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上阅读此帖子