Cannot run sonarsource/sonarcloud-github-action@master: java: not found

Hello,
I’m trying to run SonarCloud scan step using GitHub Actions on a Java project that is built using Ant. The repository is https://github.com/albertus82/earthquake-bulletin and the current workflow is https://github.com/albertus82/earthquake-bulletin/blob/ci/.github/workflows/ant.yml.

Unfortunately no scan is performed because of the following error: /opt/sonar-scanner/bin/sonar-scanner: 59: exec: /opt/hostedtoolcache/Java/8.0.222/x64/bin/java: not found. I tried also different Java versions with no luck.

Details follow:

2019-10-01T16:26:35.6130674Z ##[group]Run sonarsource/sonarcloud-github-action@master
2019-10-01T16:26:35.6130936Z env:
2019-10-01T16:26:35.6131088Z   JAVA_HOME: /opt/hostedtoolcache/Java/8.0.222/x64
2019-10-01T16:26:35.6131248Z   JAVA_HOME_8.0.222_x64: /opt/hostedtoolcache/Java/8.0.222/x64
2019-10-01T16:26:35.6131502Z   GITHUB_TOKEN: ***
2019-10-01T16:26:35.6131702Z   SONAR_TOKEN: ***
2019-10-01T16:26:35.6131842Z ##[endgroup]
2019-10-01T16:26:35.6373220Z ##[command]/usr/bin/docker run --name bb818d9079d09e204373b63877595072f20d_e53ec4 --label 04bb81 --workdir /github/workspace --rm -e JAVA_HOME -e JAVA_HOME_8.0.222_x64 -e GITHUB_TOKEN -e SONAR_TOKEN -e HOME -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/earthquake-bulletin/earthquake-bulletin":"/github/workspace" 04bb81:8d9079d09e204373b63877595072f20d
2019-10-01T16:26:39.4243128Z /opt/sonar-scanner/bin/sonar-scanner: 59: exec: /opt/hostedtoolcache/Java/8.0.222/x64/bin/java: not found
2019-10-01T16:26:39.8315733Z ##[error]Docker run failed with exit code 127

Am I missing something?

Thank you a lot.

1 Like

Solved cleaning JAVA_HOME environment variable before execution:

- if: matrix.os == 'ubuntu-latest' && matrix.java == '12' # To ensure a single execution per CI run
  uses: sonarsource/sonarcloud-github-action@master
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
    JAVA_HOME: '' # Avoid 'java: not found' error

Thank you.

3 Likes

You could also use this action:

I didn’t get why this works. What do we have to clean this up?

The action passes all the environment variables to Docker, including JAVA_HOME. This one, if present, overrides the one wired in the docker image, breaking everything.

2 Likes