Maven 构建任务因“JavaScript 堆内存不足”而失败

时间:2021-05-13 13:03:35

标签: azure maven azure-devops heap-memory

我正在使用 Azure Devops,我有一个使用 maven 构建应用程序的管道。实际上,我正在使用 Azure 任务进行构建。

  - task: Maven@3
    displayName: "Common - Build"
    inputs:
      mavenPomFile: 'web/pom.xml'
      goals: "clean install"
      options: "-Dmaven.test.skip=true -P packaging -s $(System.DefaultWorkingDirectory)/ci-maven-settings.xml -Dmaven.repo.local=$(MVN_CACHE_FOLDER)"
      publishJUnitResults: false

有时当我运行管道并启动此任务时,它会失败并显示以下错误(我在托管代理上运行它):

[ERROR] FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
[ERROR]  1: 0x8d20d0 node::Abort() [node]
[ERROR]  2: 0x8d211c  [node]
[ERROR]  3: 0xb02b6e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
[ERROR]  4: 0xb02da4 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
[ERROR]  5: 0xef02e2  [node]
[ERROR]  6: 0xef03e8 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [node]
[ERROR]  7: 0xefc512 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
[ERROR]  8: 0xefce44 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
[ERROR]  9: 0xeffab1 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [node]
[ERROR] 10: 0xec8fd4 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [node]
[ERROR] 11: 0x116846e v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [node]
[ERROR] 12: 0x222ff2edc01d 
[ERROR] error Command failed with exit code 1.

这里奇怪的是它突然发生。有时工作完美,有时失败。任务开始运行,尝试编译东西,但在某些时候它失败了。我找到的独特解决方案是重新启动管道执行。

我也尝试使用参数“mavenOption = 'Xmx2048”,任务在开始时失败,我收到以下错误:

##[error]Build failed.
##[error]Exit code 1 returned from process: file name '/home/vsts/agents/2.186.1/externals/node10/bin/node', arguments '"/home/vsts/work/_tasks/Maven_ac4ee482-65da-4485-a532-7b085873e532/3.186.0/maventask.js"'.

有没有人遇到过类似的问题?我真的很感谢这方面的任何帮助! 问候

1 个答案:

答案 0 :(得分:0)

也许你应该先添加一个cmd任务来消耗空间的大小。

在任务下添加:

set NODE_OPTIONS=--max_old_space_size=4096

enter image description here