Yos
Yos

Reputation: 41

Jenkins job hangs while pushing commits to Git repo

I'm using Jenkins 2.74.
I'm trying to push commits to the Git repo after doing changes.

This is my pipeline code:

stage('push to git') {
    steps{
        bat returnStdout: true, script: '"C:\\Program Files\\Git\\bin\\git.exe"  add -A'
        bat returnStdout: true, script: '"C:\\Program Files\\Git\\bin\\git.exe"  commit -m "upadte yaml"'
        bat returnStdout: true, script: '"C:\\Program Files\\Git\\bin\\git.exe" push -u origin master'
    }
}

But, for some reason, the job cannot be completed and it's stuck like this:

enter image description here

I tried it on my machine, using windows cmd, and it works.
But not on Jenkins.

What am I doing wrong?

Upvotes: 3

Views: 3080

Answers (4)

W. Dan
W. Dan

Reputation: 1027

I had the same problem when process git clone command by windows shell/bat in jenkins. This is my solution:

Register key in know_host file Jenkins will not auto import new key of known host to your know_host file. You can do it manually by following these steps:

  1. Login to your local account in windows
  2. SSH this git remote path directly ssh -p , type yes to register the key enter image description here
  3. Copy the registered key form local account know_host (C:\Users\something\.ssh) at the bottom omf the file you will see something like:

[gerrit.cartography.com]:29168,[10.25.174.78]:29168 ssh-rsa AAAAB3NzaC1yc2EAASSSSAQABAAAAgQDPHbDKCHL3oPbzDn3qaVZR8S1EZx/rb500Th/fjQYg5jrJ7PBMVVUyNTpJ2moje5hLYjNsVtXtcoNEZjImGul2dl3f+eHrCB27X5198jr8Wj66I/xsQCLEngd7l3velsdfgd3432fsdDiFaE9INjDjgngfNzlFA+CYpFsnaorZ6XSPQ==

  1. paste to end of 'system' know_hosts file in

    • C:\Windows\System32\config\systemprofile\.ssh
    • C:\Windows\SysWOW64\config\systemprofile\.ssh

I think you will resolve your problem now ! Enjoy it!

Upvotes: 1

조욱재
조욱재

Reputation: 41

I've solved the same problem.

Jenkins job stuck forever after executing git push command. But, same command works fine in Windows cmd.

I tried to execute git clone command as follows,

http://{GIT_ID}:{GIT_PASSWORD}@{REPOSITORY}.git

and added modifications, committed and pushed.

Then it was finished successfully.

Upvotes: 1

Yos
Yos

Reputation: 41

I got the answer, you need to check some details:

  1. ensure your Jenkins user on the Jenkins server know your git repository and the configurations
  2. Do the "Checkout" with Jenkins "git" plugin and use the SSH option (after you share the ssh keys)

That's it, i think.

Upvotes: 0

Daniel Leach
Daniel Leach

Reputation: 7375

I experienced a similar problem (pushing a tag) with git for windows version 2.13.0. Updating to 2.14.2 fixed it for me.

Upvotes: 0

Related Questions