Jenkins 上的 Bazel 本地 JDK 权限问题(Linux,CentOS)

Bazel local JDK permission issue on Jenkins (Linux, CentOS)

我发现 Jenkins 与 Bazel 存在奇怪的权限问题。该构建使用我正在准备的基于 CentOS 的 docker 图像。

21:56:37  + bazel build //src/main/java:HelloWorld
21:56:42  2021/11/10 20:56:42 Downloading https://releases.bazel.build/4.2.1/release/bazel-4.2.1-linux-x86_64...
21:56:48  Extracting Bazel installation...
21:56:49  Starting local Bazel server and connecting to it...
21:56:51  Loading: 
21:56:51  Loading: 0 packages loaded
21:56:51  Loading: 0 packages loaded
21:56:53  Loading: 0 packages loaded
21:56:53  Analyzing: target //src/main/java:HelloWorld (1 packages loaded, 0 targets configured)
21:56:55  Analyzing: target //src/main/java:HelloWorld (10 packages loaded, 18 targets configured)
21:56:55  Analyzing: target //src/main/java:HelloWorld (21 packages loaded, 285 targets configured)
21:56:57  Analyzing: target //src/main/java:HelloWorld (21 packages loaded, 285 targets configured)
21:56:58  Analyzing: target //src/main/java:HelloWorld (21 packages loaded, 285 targets configured)
21:56:59  Analyzing: target //src/main/java:HelloWorld (22 packages loaded, 322 targets configured)
21:57:02  Analyzing: target //src/main/java:HelloWorld (22 packages loaded, 322 targets configured)
21:57:02  INFO: Analyzed target //src/main/java:HelloWorld (23 packages loaded, 454 targets configured).
21:57:02  INFO: Found 1 target...
21:57:03  [0 / 4] [Prepa] BazelWorkspaceStatusAction stable-status.txt
21:57:05  ERROR: /home/jenkins/.cache/bazel/_bazel_jenkins/61c828dc7f69c1411a6e2ba3a115033a/external/bazel_tools/tools/jdk/BUILD:346:14: Action external/bazel_tools/tools/jdk/platformclasspath.jar failed: missing input file 'external/local_jdk/lib/jfr/MethodAndContention.jfc', owner: '@local_jdk//:lib/jfr/MethodAndContention.jfc': /home/jenkins/.cache/bazel/_bazel_jenkins/61c828dc7f69c1411a6e2ba3a115033a/external/local_jdk/lib/jfr/MethodAndContention.jfc (Permission denied)
21:57:05  Target //src/main/java:HelloWorld failed to build
21:57:05  Use --verbose_failures to see the command lines of failed build steps.
21:57:05  ERROR: /home/jenkins/.cache/bazel/_bazel_jenkins/61c828dc7f69c1411a6e2ba3a115033a/external/bazel_tools/tools/jdk/BUILD:346:14 Action external/bazel_tools/tools/jdk/platformclasspath.jar failed: 1 input file(s) do not exist
21:57:05  INFO: Elapsed time: 18.036s, Critical Path: 1.11s
21:57:05  INFO: 2 processes: 1 internal, 1 linux-sandbox.
21:57:05  FAILED: Build did NOT complete successfully
21:57:05  FAILED: Build did NOT complete successfully

.bazelrc 包含:

# use the JDK available in Jennkins for everything
build --host_java_toolchain=@bazel_tools//tools/jdk:toolchain_java11
build --java_toolchain=@bazel_tools//tools/jdk:toolchain_java11

我想了解的是缺少权限。 /home/jenkins 文件夹是 Jenkins 用户的用户主目录。它在那里具有完整的 read/write 权限。

JAVA_HOME 设置为 Azul OpenJDK 构建。确认有效。

有什么我应该检查的想法吗?

我做了显而易见的事情,并将以下内容添加到 Dockerfile 创建构建容器的行中。

RUN chown -R jenkins:jenkins /home/jenkins
RUN chown -R jenkins:jenkins ${JAVA_HOME}

显然默认设置不支持某些权限。现在我通过了这个问题。