Jenkins 中的堆空间问题

Posted

技术标签:

【中文标题】Jenkins 中的堆空间问题【英文标题】:Heap Space issue in Jenkins 【发布时间】:2015-01-24 17:13:00 【问题描述】:

在 Jenkins 中,我们遇到以下错误。它显示Out Of Memory Error。我将堆大小从 256 增加到 1024,但这仍然不起作用。当我将堆大小从 1024 增加到 2048 时,Jenkins 服务不起作用。我在 Jenkins.xml 文件中进行了所有这些更改。

BUILD FAILED
D:\Jenkins_Build\build_cs\cartridge\build\build.xml:2034: The following error occurred while executing this line:
D:\Jenkins_Build\build_cs\cartridge\build\build.xml:1662: java.lang.OutOfMemoryError: Java heap space
    at java.util.Arrays.copyOf(Unknown Source)
    at java.io.ByteArrayOutputStream.grow(Unknown Source)
    at java.io.ByteArrayOutputStream.ensureCapacity(Unknown Source)
    at java.io.ByteArrayOutputStream.write(Unknown Source)
    at org.apache.commons.httpclient.methods.InputStreamRequestEntity.bufferContent(InputStreamRequestEntity.java:137)
    at org.apache.commons.httpclient.methods.InputStreamRequestEntity.getContentLength(InputStreamRequestEntity.java:187)
    at org.apache.commons.httpclient.methods.EntityEnclosingMethod.getRequestContentLength(EntityEnclosingMethod.java:336)
    at org.apache.commons.httpclient.methods.EntityEnclosingMethod.addContentLengthRequestHeader(EntityEnclosingMethod.java:406)
    at org.apache.commons.httpclient.methods.EntityEnclosingMethod.addRequestHeaders(EntityEnclosingMethod.java:374)
    at org.apache.commons.httpclient.HttpMethodBase.writeRequestHeaders(HttpMethodBase.java:2177)
    at org.apache.commons.httpclient.HttpMethodBase.writeRequest(HttpMethodBase.java:2060)
    at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1096)
    at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
    at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
    at com.demandware.deploy.WebDavHelper.doPutAndUnzip(WebDavHelper.java:152)
    at com.demandware.deploy.WebDavHelper.uploadZip(WebDavHelper.java:87)
    at com.demandware.deploy.DeployCartridgesTask.execute(DeployCartridgesTask.java:148)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
    at net.sf.antcontrib.logic.IfTask.execute(IfTask.java:217)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)

【问题讨论】:

【参考方案1】:

您执行 ant 构建。因此,您必须增加 ant build 的堆,而不是 jenkins 服务器的堆。

看看How to use the `Java Options` in jenkins ant build tool to set ANT_OPTS

【讨论】:

以上是关于Jenkins 中的堆空间问题的主要内容,如果未能解决你的问题,请参考以下文章

当 Jenkins 在 Ubuntu 上作为守护进程运行时,如何给它更多的堆空间?

当 Jenkins 在 Ubuntu 上作为守护进程运行时,如何给它更多的堆空间?

詹金斯中的堆空间错误

Jenkins powershell脚本中的转义空间和解析变量不起作用

Jenkins 中的 PermGen 错误

jenkins 更改工作空间