I have a GitLab CI pipeline that uses by default, in all stages, the Temurin Docker (Linux) image for Java.
I need to expand the build targets to use several operating systems: Linux, macOS, Windows. So if there were the following Docker images: eclipse-temurin:21-jdk-jammy
, eclipse-temurin:21-jdk-nanoserver
, and eclipse-temurin:21-jdk-macos
, is there a way to run a given job against all those Docker images, without repeating the job definitions?
The initial route I'm taking is to use GitLab CI's matrix
but it's not quite working:
assemble:
image: eclipse-temurin:21-jdk-${OS}
parallel:
matrix:
- OS: [jammy, nanoserver]
script:
- ./gradlew packageDistributionForCurrentOS
stage: assemble
I see the Docker images are resolved correctly, but somehow the GitLab runner fails for eclipse-temurin:21-jdk-nanoserver
:
Running with gitlab-runner 16.6.0~beta.105.gd2263193 (d2263193)
on blue-5.saas-linux-small-amd64.runners-manager.gitlab.com/default -AzERasQ, system ID: s_4cb09cee29e2
feature flags: FF_USE_IMPROVED_URL_MASKING:true
Preparing the "docker+machine" executor 00:05
Using Docker executor with image eclipse-temurin:21-jdk-nanoserver ...
Pulling docker image eclipse-temurin:21-jdk-nanoserver ...
WARNING: Failed to pull image with policy "always": no matching manifest for linux/amd64 in the manifest list entries (manager.go:237:0s)
ERROR: Job failed: failed to pull image "eclipse-temurin:21-jdk-nanoserver" with specified policies [always]: no matching manifest for linux/amd64 in the manifest list entries (manager.go:237:0s)
This error doesn't tell me much. I can only infer that the Docker image eclipse-temurin:21-jdk-nanoserver
is not available for the linux/amd64
architecture, and that may be what the GitLab runner's host machine is actually mounted on, but these Docker images should be agnostic to the infrastructure, and 21-jdk-nanoserver
is indeed a Windows image.
Any suggestions on how to move forward with this approach to achieve this desired behavior?
The issue here is your GitLab runner looks to have an architecture of linux/amd64
but your trying to pull the docker tag 21-jdk-nanoserver
which is only built for windows architectures. So you cannot run this tag version of the image on Linux.
So either change to use a tag that's built for the Linux architecture of your GitLab runner, or update your runner tags to be able to run this image on a windows runner.
Expanding on Doyle's answer a little bit more — the final solution could look like:
assemble:
artifacts:
paths:
- $CI_PROJECT_DIR/build/libs/
image: eclipse-temurin:21-jdk-$OS
parallel:
matrix:
- PLATFORM: linux
OS: jammy
RUNNER: saas-linux-medium-amd64
- PLATFORM: windows
OS: nanoserver
RUNNER: saas-windows-medium-amd64
script:
- ./gradlew packageDistributionForCurrentOS $GRADLE_EXTRA_OPTS
stage: assemble
tags:
- $RUNNER
This run fine in both Linux and Windows.
Running with gitlab-runner 16.5.0 (853330f9)
on gitlab-com-saas-windows-medium-amd64 ..., system ID: ...
Preparing the "custom" executor 04:42
Using Custom executor with driver autoscaler 0.1.3 (4f53eb0)...
Creating virtual machine for the job...
Virtual machine created!
...
$ ./gradlew packageDistributionForCurrentOS
Daemon will be stopped at the end of the build
> Configure project :
Kotlin DSL property assignment is an incubating feature.
> Task :checkRuntime
> Task :checkKotlinGradlePluginConfigurationErrors
> Task :processResources
> Task :compileKotlin
> Task :createRuntimeImage
> Task :compileJava NO-SOURCE
> Task :classes
> Task :jar
> Task :prepareAppResources NO-SOURCE
> Task :unpackDefaultComposeDesktopJvmApplicationResources
> Task :downloadWix
Download https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311-binaries.zip
> Task :unzipWix
> Task :packageMsi
...
> Task :packageDistributionForCurrentOS
BUILD SUCCESSFUL in 6m 41s
10 actionable tasks: 10 executed
...
Job succeeded