Usage of jlink in jenkinsci/docker-agent

Hi,

I built a Jenkins agent and encountered the following error:

[1/3] STEP 9/9: RUN case "$(jlink --version 2>&1)" in       "11."*) set -- "--strip-debug" "--compress=2" ;;       "17."*) set -- "--strip-java-debug-attributes" "--compress=2" ;;       "21."*) set -- "--strip-java-debug-attributes" "--compress=zip-6" ;;       *) echo "ERROR: unmanaged jlink version pattern" && exit 1 ;;     esac;     jlink       "$1"       "$2"       --add-modules ALL-MODULE-PATH       --no-man-pages       --no-header-files       --output /javaruntime
Error: Cannot read field "W" because "this" is null
java.lang.NullPointerException: Cannot read field "W" because "this" is null
	at java.base/sun.security.provider.SHA2.implCompress0(SHA2.java:161)
	at java.base/sun.security.provider.SHA2.implCompress(SHA2.java:135)
	at java.base/sun.security.provider.DigestBase.implCompressMultiBlock0(DigestBase.java:149)
	at java.base/sun.security.provider.DigestBase.implCompressMultiBlock(DigestBase.java:143)
	at java.base/sun.security.provider.DigestBase.engineUpdate(DigestBase.java:130)
	at java.base/java.security.MessageDigest$Delegate.engineUpdate(MessageDigest.java:653)
	at java.base/java.security.MessageDigest.update(MessageDigest.java:347)
	at java.base/jdk.internal.module.ModuleHashes.lambda$computeHash$0(ModuleHashes.java:125)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
	at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:357)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
	at java.base/jdk.internal.module.ModuleHashes.computeHash(ModuleHashes.java:120)
	at java.base/jdk.internal.module.ModuleHashes.computeHash(ModuleHashes.java:148)
	at java.base/jdk.internal.module.ModuleReferences.lambda$newJModModule$3(ModuleReferences.java:105)
	at java.base/jdk.internal.module.ModuleReferenceImpl.computeHash(ModuleReferenceImpl.java:153)
	at java.base/java.lang.module.Resolver.checkHashes(Resolver.java:475)
	at java.base/java.lang.module.Resolver.finish(Resolver.java:378)
	at java.base/java.lang.module.Configuration.<init>(Configuration.java:139)
	at java.base/java.lang.module.Configuration.resolve(Configuration.java:422)
	at java.base/java.lang.module.Configuration.resolve(Configuration.java:254)
	at jdk.jlink/jdk.tools.jlink.internal.Jlink$JlinkConfiguration.resolve(Jlink.java:217)
	at jdk.jlink/jdk.tools.jlink.internal.JlinkTask.createImageProvider(JlinkTask.java:523)
	at jdk.jlink/jdk.tools.jlink.internal.JlinkTask.createImage(JlinkTask.java:411)
	at jdk.jlink/jdk.tools.jlink.internal.JlinkTask.run(JlinkTask.java:286)
	at jdk.jlink/jdk.tools.jlink.internal.Main.run(Main.java:56)
	at jdk.jlink/jdk.tools.jlink.internal.Main.main(Main.java:34)
Error: building at STEP "RUN case "$(jlink --version 2>&1)" in       "11."*) set -- "--strip-debug" "--compress=2" ;;       "17."*) set -- "--strip-java-debug-attributes" "--compress=2" ;;       "21."*) set -- "--strip-java-debug-attributes" "--compress=zip-6" ;;       *) echo "ERROR: unmanaged jlink version pattern" && exit 1 ;;     esac;     jlink       "$1"       "$2"       --add-modules ALL-MODULE-PATH       --no-man-pages       --no-header-files       --output /javaruntime": while running runtime: exit status 4

It’s part of the standard Dockerfile of the Alpine build:

I was building with the following command (for my Raspberry):

buildah bud --arch arm64/v8 --build-arg=JAVA_VERSION=21.0.3_9 -f alpine/Dockerfile  -t jenkins-agent .

Interestingly, the same build succeeded without the error when building on the native platform of the host (x86_64 OpenSuse Tumbleweed):

buildah bud --build-arg=JAVA_VERSION=21.0.3_9 -f alpine/Dockerfile  -t jenkins-agent .

I was just wondering if anyone encountered this or similar issues?

I’m pretty sure it has to do with how I start the build process. I saw that the repository suggests to build with docker bake (docker-agent/docker-bake.hcl at d0dc0081b54dd1368cce245d74842c8f36aae10d · jenkinsci/docker-agent · GitHub) but this is not an option for me right now.

I can work around the issue right now by not creating a minimal build and simply include the full blown jdk in the image.