Gitlab CI, JAVA_HOME not set

Viewed 23

I was trying for some hours ago to get Gitlab CI finished successfully. But I always get an error, when trying to connect to DB. I have a python project, which connect to h2 in-memory database, that's why the project also needs java.

Here is my .gitlab-ci.yml file:

stages:          
  - test

image: python:latest

before_script:
  - python3 -V
  
unit-test-job:   
  stage: test    
  script:
    - pip install -r requirements.txt
    - pip install jaydebeapi
    - python -m unittest fetchdata_test
    - python -m unittest db_test

And here is the error i get:

======================================================================
ERROR: test_writeToDB (fetchdata_test.TestFetchdata)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/builds/rest-api-calls-in-each-of-java-python-and-node-js/python/fetchdata_test.py", line 13, in test_writeToDB
    db.initDB()
  File "/builds/rest-api-calls-in-each-of-java-python-and-node-js/python/db.py", line 37, in initDB
    result = execute(createCountryTableQuery)
  File "/builds/rest-api-calls-in-each-of-java-python-and-node-js/python/db.py", line 26, in execute
    connection  = jaydebeapi.connect("org.h2.Driver", "jdbc:h2:mem:covid19;DB_CLOSE_DELAY=-1", ["sa", ""],
  File "/usr/local/lib/python3.10/site-packages/jaydebeapi/__init__.py", line 412, in connect
    jconn = _jdbc_connect(jclassname, url, driver_args, jars, libs)
  File "/usr/local/lib/python3.10/site-packages/jaydebeapi/__init__.py", line 184, in _jdbc_connect_jpype
    jvm_path = jpype.getDefaultJVMPath()
  File "/usr/local/lib/python3.10/site-packages/jpype/_jvmfinder.py", line 74, in getDefaultJVMPath
    return finder.get_jvm_path()
  File "/usr/local/lib/python3.10/site-packages/jpype/_jvmfinder.py", line 212, in get_jvm_path
    raise JVMNotFoundException("No JVM shared library file ({0}) "
jpype._jvmfinder.JVMNotFoundException: No JVM shared library file (libjvm.so) found. Try setting up the JAVA_HOME environment variable properly.
----------------------------------------------------------------------
Ran 2 tests in 0.454s
FAILED (errors=1)

I've tried a lot from the internet/stackoverflow but nothing works, like inserting the openjdk, maven as a service ect.

Any help, please?

1 Answers

After long search, I found the solution.

stages:          
  - test

image: python:latest

services:
  - openjdk:11-jre-slim-buster

before_script:
  - apt-get update
  - apt-get install default-jdk -y
  - pip install -r requirements.txt
  - pip install jaydebeapi
    
unit-test-job:   
  stage: test    
  script:
    - python -m unittest discover

After adding openjdk:11-jre-slim-buster as a service and running following code, it works:

- apt-get update
- apt-get install default-jdk -y
Related