Saturday, February 26, 2022

[SOLVED] Jenkins "Error cloning remote repo 'origin'" and "Cannot allocate memory"

Issue

I have Jenkins running on my server connected with GitHub via webhooks. Unfortunately my builds are failing OCCASIONALLY and I can't figure out why. Sometimes restarting Jenkins (sudo service jenkins restart) solves the problem, sometimes it doesn't. The server is running Ubuntu 16.04 nad Nginx as a proxy. What causes this issue and how can I solve it?

Started by GitHub push by gaboratorium
Building in workspace /var/lib/jenkins/workspace/kudos.gaboratorium.com
[WS-CLEANUP] Deleting project workspace...
[WS-CLEANUP] Done
Cloning the remote Git repository
Cloning repository https://github.com/gaboratorium/kudos.git
> git init /var/lib/jenkins/workspace/kudos.gaboratorium.com # timeout=10
Fetching upstream changes from https://github.com/gaboratorium/kudos.git
> git --version # timeout=10
> git fetch --tags --progress https://github.com/gaboratorium/kudos.git 
+refs/heads/*:refs/remotes/origin/*
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Command "git fetch --tags --progress 
https://github.com/gaboratorium/kudos.git 
+refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: error: cannot fork() for fetch-pack: Cannot allocate memory

at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1903)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1622)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:71)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:348)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:545)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1070)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1110)
at hudson.scm.SCM.checkout(SCM.java:495)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1276)
at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:560)
at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:485)
at hudson.model.Run.execute(Run.java:1735)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:405)
ERROR: Error cloning remote repo 'origin'
Finished: FAILURE

Solution

Turned out, it was an OOM (out-of-memory) problem, which could be easy solved by creating some swap space. To do that, I have followed this guide, which solved my issue perfectly: https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04

Also, I have made some notes about the setup myself as well. If you are having issues you might find it helpful: https://archives.gaboratorium.hu/continuous-integration-with-jenkins



Answered By - Gábor Pintér
Answer Checked By - Candace Johnson (WPSolving Volunteer)