Issue while using uses: sonarsource/sonarcloud-github-action@master

Template for a good new topic, formatted with Markdown:

  • ALM used (GitHub, Bitbucket Cloud, Azure DevOps)
  • CI system used - github action
  • Scanner command used when applicable (private details masked)
  • Languages of the repository
  • Only if the SonarCloud project is public, the URL
    • And if you need help with pull request decoration, then the URL to the PR too
  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting)
/home/runner/work/_temp/b182405e-fe35-4d9c-aa9a-feb2f4a243a3.sh: line 2: -Dsonar.pullrequest.branch=feat/<branch_name>: No such file or directory

[482](https://github.com/<org_name>/<repo_name>/actions/runs/12257616714/job/34250403096#step:5:490)Error: Process completed with exit code 127.
  • Steps to reproduce:
    We have github action workflow configured which uses following:
- name: Push result to SonarCloud server
        uses: sonarsource/sonarcloud-github-action@master
        with:
          args: |
            -Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
            -Dsonar.pullrequest.branch=${{ github.head_ref }}
            -Dsonar.pullrequest.base=${{ github.base_ref }}
        env:
          GITHUB_TOKEN: ${{ secrets.SVC_DOT_BOT_GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_CLOUD_TOKEN }}

With the above configurations things were working fine until week before but now workflows are failing with the above mentioned error.

  • Potential workaround
    As a workaround I switched to uses: sonarsource/sonarcloud-github-action@v3.1.0 and now pipeline is working as expected. Can you please help me troubleshot the issue. I even tried using uses: sonarsource/sonarqube-scan-action@master but still pipeline fails with the above error.

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

Hi @deepika22,

I think the issue is in the use of | (that preserve newlines) to add multiple arguments to the Sonar Scanner CLI via args:

args: |
  -Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
  -Dsonar.pullrequest.branch=${{ github.head_ref }}
  -Dsonar.pullrequest.base=${{ github.base_ref }}

Can you please try to use > (that inlines) instead:

args: >
  -Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
  -Dsonar.pullrequest.branch=${{ github.head_ref }}
  -Dsonar.pullrequest.base=${{ github.base_ref }}

Let me know if that fixes your problem,
Best regards,
Antonio

Hi again,

I have just run another test, and >- (stripping all newlines, including the last one) also works.
See here for further info.
What is important is to resolve all options on a single line.

With the above configurations things were working fine until week before but now workflows are failing with the above mentioned error.

It would help to have logs for one of your failed runs and one of your successful runs on v3.1.0, in particular where the Sonar Scanner CLI is called. Something like the following:

Cache restored successfully
Cache restored from key: sonar-scanner-cli-6.2.1.4610-Linux-X64
Run echo "${RUNNER_TEMP}/sonar-scanner-cli-6.2.1.4610-Linux-X64/bin" >> $GITHUB_PATH
Run ${GITHUB_ACTION_PATH}/run-sonar-scanner.sh -Dsonar.projectKey=dart-project -Dsonar.login=admin -Dsonar.*** --debug
  ${GITHUB_ACTION_PATH}/run-sonar-scanner.sh -Dsonar.projectKey=dart-project -Dsonar.login=admin -Dsonar.*** --debug
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    SONAR_HOST_URL: http://localhost:9000
    INPUT_PROJECTBASEDIR: ./dart-project
    SONAR_SCANNER_JRE: /home/runner/work/_temp/sonar-scanner-cli-6.2.1.4610-Linux-X64/jre
+ sonar-scanner -Dsonar.projectBaseDir=./dart-project -Dsonar.projectKey=dart-project -Dsonar.login=admin -Dsonar.*** --debug
14:16:18.910 INFO  Scanner configuration file: /home/runner/work/_temp/sonar-scanner-cli-6.2.1.4610-Linux-X64/conf/sonar-scanner.properties
14:16:18.913 INFO  Project root configuration file: NONE
14:16:18.928 INFO  SonarScanner CLI 6.2.1.4610

My hypothesis is that v3.1.0 (the Docker-based version of the GitHub action) flattened parameters to a single line, when specified as a multiline string, whereas v4.0.0 does not.

Best regards,
Antonio

I just tried using following and it worked.

args: >
  -Dsonar.pullrequest.key=${{ github.event.pull_request.number }}
  -Dsonar.pullrequest.branch=${{ github.head_ref }}
  -Dsonar.pullrequest.base=${{ github.base_ref }}
1 Like

Great news!

Though the warning is there which I suppose should go with using sonarqube-scan-action@v4.1.0. I think its better to use specific version instead of using master.

Run echo β€œ::warning title=SonarScanner::This action is deprecated and will be removed in a future release. Please use the sonarqube-scan-action action instead. The sonarqube-scan-action is a drop-in replacement for this action.”

30Warning: This action is deprecated and will be removed in a future release. Please use the sonarqube-scan-action action instead. The sonarqube-scan-action is a drop-in replacement for this action.

Yes, the warning should disappear as soon as you switch to sonarqube-scan-action@v4.1.0.
The change from sonarcloud-github-action@v4.0.0 to sonarqube-scan-action@v4.1.0 should be painless, since sonarcloud-github-action@v4.0.0 just forwards to sonarqube-scan-action@v4.1.0.

So I encourage you to try sonarqube-scan-action out, and open a new issue in the community if you encounter any problem.

I agree it’s better to use a fix version, rather than master, to avoid breaking main pipelines when an issue arises.

Best regards,
Antonio

Thanks for your quick help. Really appreciate it!!

1 Like