File was unable to be removed Error: EACCES: permission denied, unlink 'scannerwork/.sonar_lock'

I am using SonarCloud and I am trying to run the GitHub workflow on a Linux based self-hosted runner. I have a workflow for frontend javascript, typescript project and everytime the scan runs, the subsequent scans fail stating that

File was unable to be removed Error: EACCES: permission denied, unlink ‘scannerwork/.sonar_lock’

I will have to manually delete the sonar_lock file and then only the other scans run.

This issue doesn’t happen when I run the sonar scan workflow for a BE project (.Net) on the self-hosted runner. It only happens for the FE workflow as below.

This is the workflow I am running

sonarcloud-scan-frontend:
    needs: changes
    runs-on: self-hosted
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
        with:
          fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

      - name: set node to 16
        uses: actions/setup-node@v3
        with:
          node-version: "16"

      - name: set npm to 6
        run: npm i -g npm@6

      - name: install dependencies
        working-directory: ./UI/QueryBuilder
        run: npm ci

      - name: run tests
        working-directory: ./UI/QueryBuilder
        run: npm test --coverage --coverageReporters lcov

      - name: SonarCloud Scan
        uses: SonarSource/sonarcloud-github-action@master
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        with:
          projectBaseDir: ./UI/QueryBuilder

What am I missing here?

Hey there.

It looks like a similar issue was reported on the sonarqube-scan-action: Action leaves .scannerwork owned by root · Issue #22 · SonarSource/sonarqube-scan-action · GitHub

A workaround is available in that ticket, and I’ll flag this for attention from the team responsible for the SonarCloud action.

We are working on a fix, we’ll have it released soon.

Good news, sonarcloud-github-action v2.1.0 has been released which includes a fix for this issue. Let us know if the issue persists.

1 Like

Thank you for the quick action. I will check and update you.

The scans are running fine now without any errors on the self-hosted runner. Thank you!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.