Reputation: 105
I would like clarification on:
Right now, I believe that the Master Node stores all credentials and then passes these credentials to the worker agents. This makes me believe that only one node - the master node - should have ssh keys for git.
Thus far this seems to be true because, when a build is trigged on master, the worker node is able to run git clone and git init even though no ssh keys are configured on worker agent.
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
So why then does this step:
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')
}
result in this error:
[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
this line from the error print out above:
fatal: could not read Username for 'https://github.com': No such device or address
completely throws me off because I have no idea where it is looking for a username.
Can someone please help me out? Thanks.
Upvotes: 1
Views: 4702
Reputation: 105
This:
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')
}
fails because credentials that are defined in Master Node are not automatically bound/passed into build jobs.
To bind credentials, we need the suite of Credentials Plugins. Once those are installed, then we make use of the withCredentials() function to pass in the credentials needed to authenticate/communicate with git.
Read this post on jenkins-user forum if you need more clarification
Upvotes: 1