我在Mac Mini上運行一個Jenkins版本的Android項目(10.9.5)。詹金斯構建與像這樣的錯誤消息失敗:爲詹金斯/ gradle增加PermGen空間
<package>.myTest > test_myTest FAILED
org.mockito.cglib.core.CodeGenerationException at test_myTest.java:65
Caused by: java.lang.reflect.InvocationTargetException at test_myTest.java:65
Caused by: java.lang.OutOfMemoryError at test_myTest.java:65
java.lang.OutOfMemoryError: PermGen space
這有時隨後的消息像
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "/0:0:0:0:0:0:0:1:50340 to /0:0:0:0:0:0:0:1:50339 workers Thread 2"
16:47:17
16:47:17 Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "/0:0:0:0:0:0:0:1:50340 to /0:0:0:0:0:0:0:1:50339 workers Thread 4"
16:47:18
16:47:18 Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "/0:0:0:0:0:0:0:1:50340 to /0:0:0:0:0:0:0:1:50339 workers Thread 5"
16:47:18
16:47:18 Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "/0:0:0:0:0:0:0:1:50340 to /0:0:0:0:0:0:0:1:50339 workers Thread 6"
16:47:19
它通常無法在構建的相同點。根據Jenkins wiki
你是否一直在構建的同一階段看到OOME?如果是這樣,也許它只需要更大的內存。
這可能意味着我只需要更多的PermGen空間。
我讀過的stackoverflow文章/博客文章表明我需要增加最大PermGen大小(例如,-XX:MaxPermSize=1024M
)。但是,我不清楚在哪裏可以做到這一點。
我已經改變了這對GRADLE_OPTS
和JAVA_OPTS
所以我的詹金斯生成環境是這樣的:
如截圖所見,我還添加了一些選項,垃圾回收燙髮根建議here。
這似乎是行得通的 - 昨天我有一些成功的構建,但現在失敗了(沒有我知道的變化)。
讀完this answer後,我在項目的gradle.properties
文件中也更改了下面一行。
org.gradle.jvmargs=-Xms1024M -Xmx2048M -XX:PermSize=512M -XX:MaxPermSize=2048 -XX:+CMSClassUnloadingEnabled -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
這並沒有解決問題。
類似問題的答案,如this和this讓我覺得我可能正在接近這個錯誤的方式 - 我應該改變運行Jenkins的Mac(10.9.5)的計算機設置嗎?什麼是修改PermGen空間的正確方法?
編輯:我以前想過,也許環境變量沒有被確定,但我證實它們出現在構建結果的環境變量(jenkins/job/<Project>/146/injectedEnvVars/
)
謝謝你的迴應!我沒有意識到測試是在單獨的JVM上運行的,所以你的回答讓我走上了正確的軌道。等待期結束後,我會獎勵賞金。 – Michiyo