2
votes

I faced error when I try to build my Gitlab project in Jenkins.

What I tried

  1. Set the system environment as Setup your environment variables for Git Plugin Jenkins
  2. Under “git” change “Path to Git executable” to GIT_FOLDER\cmd\git.cmd (NOT GIT_FOLDER\bin\git.exe)
  3. Using PsExec.exe to let the “Local System account” accessed by Jenkins server to have SSH keys or known_hosts set up and verify via

    "GIT_FOLDER\bin\ssh.exe" -T [email protected]

  4. Even success to fetch via the same command in the

    "C:\Program Files (x86)\Git\bin\sh.exe" -login -i window

  5. Fill in the Gitlab host url and API Token for Jenkins account in Gitlab server

  6. Create credential with ssh key with no passphrase and selected in project credential

Jenkins Build Error Log

(git_repository.git represents my git repository url)

Started by user Jenkins

Building in workspace C:\Program Files (x86)\Jenkins\jobs\MyApp-Test\workspace

C:\Program Files (x86)\Git\bin\git.exe rev-parse --is-inside-work-tree # timeout=10

Fetching changes from the remote Git repository

C:\Program Files (x86)\Git\bin\git.exe config remote.origin.url git_repository.git # timeout=10

Fetching upstream changes from git_repository.git

C:\Program Files (x86)\Git\bin\git.exe --version # timeout=10

using GIT_SSH to set credentials

C:\Program Files (x86)\Git\bin\git.exe -c core.askpass=true fetch --tags --progress git_repository.git +refs/heads/:refs/remotes/origin/

ERROR: Timeout after 10 minutes
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from git_repository.git
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:735)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:983)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1016)
at hudson.scm.SCM.checkout(SCM.java:485)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1282)
at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:610)
at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:532)
at hudson.model.Run.execute(Run.java:1741)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:381)
Caused by: hudson.plugins.git.GitException: Command "C:\Program Files (x86)\Git\bin\git.exe -c core.askpass=true fetch --tags --progress git_repository.git +refs/heads/*:refs/remotes/origin/*" returned status code -1:
stdout: 
stderr: 
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1591)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1379)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:86)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:324)
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:733)
... 11 more
ERROR: Error fetching remote repo 'origin'
2
It is not related to timeout actually in my case.V-SHY

2 Answers

5
votes

Change the credential of the free style project to default option - none -

Because the ssh will use the API token of the Gitlab plugin value to access to the Gitlab server.

Therefore if you specify another SSH key to access the Gitlab server in the project, they will stuck forever.

This took my one week to find this out.

0
votes

I got the same error when I mistakenly created a .git folder in the remote application folder. Deleting the folder fixed it.