I would like to invoke the java command as part of a Gitlab pipeline.
The pipeline looks like:
build:
image: docker:stable
stage: build
script:
- wget https://download.oracle.com/graalvm/23/latest/graalvm-jdk-23_linux-x64_bin.tar.gz
- tar -xvf graalvm-jdk-23_linux-x64_bin.tar.gz
- mv graalvm-jdk-23.0.1+11.1 /opt/
- JAVA_HOME='/opt/graalvm-jdk-23.0.1+11.1'
- PATH="$JAVA_HOME/bin:$PATH"
- echo $PATH
- export PATH
- java --version
# // later here will download maven, compile a graalvm native image, and docker push it
variables:
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_TLS_VERIFY: 1
DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client"
services:
- docker:dind
However, when trying to execute the java command, I am getting: /bin/sh: eval: line 155: java: not found
I tried moving the folder, chmod 777, providing relative, absolute path, but always getting /bin/sh: eval: line 155: java: not found
.
I was expecting this step, the invocation of java --version to succeed.
How to invoke java command properly?
I would suggest to use graalvm image directly instead of slim docker image
In download page there are container options already, you can see both images with maven work below
variables:
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_TLS_VERIFY: 1
DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client"
services:
- docker:dind
stages:
- build
build-with-native-image:
stage: build
image: container-registry.oracle.com/graalvm/native-image:23
script:
- microdnf install unzip zip findutils
- java --version
- native-image --version
- curl -s "https://get.sdkman.io" | bash
- source "$HOME/.sdkman/bin/sdkman-init.sh"
- sdk install maven
- mvn package
# Job using the JDK container
build-with-jdk:
stage: build
image: container-registry.oracle.com/graalvm/jdk:23
script:
- microdnf install unzip zip findutils
- java --version
- curl -s "https://get.sdkman.io" | bash
- source "$HOME/.sdkman/bin/sdkman-init.sh"
- sdk install maven
- mvn test
Running example here
The problem in the yml is using docker:stable
which is stripped from everything, even glibc does not exist in the container, So below you can see debian based docker image and do the firther steps with scripts
build:
image: debian:bullseye-slim
stage: build
script:
- apt-get update && apt-get install -y wget tar
- wget https://download.oracle.com/graalvm/23/latest/graalvm-jdk-23_linux-x64_bin.tar.gz
- tar -xvf graalvm-jdk-23_linux-x64_bin.tar.gz
- mv graalvm-jdk-23.0.1+11.1 /opt/
- JAVA_HOME=/opt/graalvm-jdk-23.0.1+11.1
- export PATH="$JAVA_HOME/bin:$PATH"
- /opt/graalvm-jdk-23.0.1+11.1/bin/java --version
- java --version
# // later here will download maven, compile a graalvm native image, and docker push it
variables:
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_TLS_VERIFY: 1
DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client"
services:
- docker:dind
Working example here