【问题标题】:Gradle build on GitLab CI: Could not create service of type ScriptPluginFactoryGradle 在 GitLab CI 上构建:无法创建 ScriptPluginFactory 类型的服务
【发布时间】:2018-11-07 21:39:04
【问题描述】:

GitLab CI 上使用 并行 Gradle 作业:

我收到以下 随机 Gradle 异常:

FAILURE: Build failed with an exception.

* What went wrong:
Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().
> Could not create service of type ResourceSnapshotterCacheService using GradleUserHomeScopeServices.createResourceSnapshotterCacheService().

我使用 gitlab-runnerdocker 执行程序,没有任何 GitLab CI 缓存。我使用 Docker 卷而不是 Gradle 缓存指向该卷:

before_script:
  - export GRADLE_USER_HOME=/pipelines/.gradle

/pipelines 目录的访问权限没有问题(所以它不是 this question 的重复)。

这个问题的简单但烦人的解决方法是手动重新触发失败的作业 - 然后它会顺利通过。另一种解决方法是通过retry 指令自动重新触发作业。

所以,我的问题是:是什么导致了作业失败以及如何解决它(无需重新触发作业)

【问题讨论】:

    标签: docker gradle gitlab-ci gitlab-ci-runner


    【解决方案1】:

    根本原因:

    经过一些调试(切换--stacktrace--info),很明显根本原因是多个Docker容器在主机上共享一个Gradle缓存机器。

    Caused by: org.gradle.cache.LockTimeoutException: Timeout waiting to lock file hash cache (/pipelines/.gradle/caches/4.10.2/fileHashes). It is currently in use by another Gradle instance.
    Owner PID: 158
    Our PID: 160
    Owner Operation: 
    Our operation: 
    Lock file: /pipelines/.gradle/caches/4.10.2/fileHashes/fileHashes.lock
    

    解决方案:

    还有未解决的 Gradle 错误/功能:Let multiple containers share downloaded dependencies。因此,我(重新)为每个涉及的 GitLab CI 作业实现了适当的 Gradle 缓存(因此,没有共享缓存?):

    before_script:
      - export GRADLE_USER_HOME=`pwd`/.gradle
    
    rpmClient:
      stage: buildRpm
      script:
      - gradle clientRpm
      cache:
        paths:
        - .gradle/caches
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-07
      • 1970-01-01
      • 1970-01-01
      • 2019-09-26
      • 1970-01-01
      • 2016-02-25
      相关资源
      最近更新 更多