0

For running my Node.js tests (which require Java) I used this configuriation:

version: 2.1

orbs:
  node: circleci/node@4.7.0
  
jobs:
  build_and_test:
    docker:
      - image: cimg/openjdk:17.0.2-node
    resource_class: large
    steps:
      - checkout
      - run: java --version
      - run: node --version
      - node/install-packages:
          pkg-manager: npm
      - run:
          command: npm run test
          name: Run tests
            
workflows:
    validation:
        jobs:
            - build_and_test
            

As you can see I use the language variant for the OpenJDK with Node. The version checks both succeed, so Java is actually available.

However, when I spawn a process in my tests to run Java, it fails:

            const java = child_process.spawn("java", parameters, spawnOptions);
            if (!java.connected) {
                resolve("Java not installed");

                return;
            }

Is there something special I have to consider when spawing processes in CircleCI or is something else required, which I haven't done yet?

Mike Lischke
  • 48,925
  • 16
  • 119
  • 181

1 Answers1

-1

The problem is the check for the process. While this works well locally, it does not in environments like CircleCI. Instead use the error event of the child process, like:

            java.on("error", (error) => {
                resolve(`Error while running Java: "${error.message}". Is Java installed on you machine?`);
            });


Mike Lischke
  • 48,925
  • 16
  • 119
  • 181
  • This does not provide a solution. How do we get java in the CI environment? – Haider Malik Jul 11 '23 at 13:48
  • This indeed provides a solution. I have used it for a while until I switched to GH actions. You get Java in your CI environment by specifying ` docker: - image: cimg/openjdk:17.0.2-node`. – Mike Lischke Jul 12 '23 at 07:01