Gradle 在 GitLab CI 上构建:无法创建 ScriptPluginFactory 类型的服务

Vít*_*čka 2 gradle docker gitlab-ci gitlab-ci-runner

在GitLab CI上使用并行 Gradle作业:

并行 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().
Run Code Online (Sandbox Code Playgroud)

我使用没有任何GitLab CIdocker缓存的执行器。我使用Docker卷,而Gradle缓存指向该卷:gitlab-runner

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().
Run Code Online (Sandbox Code Playgroud)

目录的访问权限没有问题/pipelines(所以这不是这个问题的口是心非)。

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

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

Vít*_*čka 5

根本原因:

经过一番调试(切换--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
Run Code Online (Sandbox Code Playgroud)

解决方案:

仍然存在未解决的Gradle bug/feature:让多个容器共享下载的依赖项。因此,我(重新)为每个涉及的GitLab CI作业实现了适当的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
Run Code Online (Sandbox Code Playgroud)