2017-10-08 52 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上阅读本文