Updated on 2026-08-04 GMT+08:00

Creating an Automatic Code Check Task on SonarQube

Configuring Automatic Code Check

  1. Use your GitHub account to log in to the SonarQube homepage.
  2. Click Favorite projects on the navigation bar and click Configure analysis.

    Figure 1 Configuring code check

  3. Click With GitHub Actions to go to the page for configuring the interconnection between SonarQube and GitHub Actions.

  4. Click Settings > Secrets and variables > Actions and select Python (Python is used for coding in this practice) to open the page for creating a secret for the target code repository.

    Figure 2 Parameters for interconnecting with GitHub Actions

  5. Click New repository secret to open the page for entering secret information.

    Figure 3 Configuring a secret

  6. Copy the values of Name and Value in 4 and paste them to the Name and Secret text boxes on the page for adding a secret. Click Add secret.

    Figure 4 Entering secret parameters

  7. After the secret is successfully configured on GitHub, return to the SonarQube page that was opened in 4. Click Python, Windows, and then Copy to copy the secret, and save it to the local PC.

  8. Log in to GitHub. On the homepage of the url-link-extractor repository, click to go to the branch page of the repository. Click New branch in the upper right corner, enter the name of the new code branch in the New branch name text box, and click Create new branch. In this practice, enter the branch name develop.
  9. Click develop to go to the code home page of the develop branch.

    Figure 5 Opening the home page of the develop branch

  10. Click Add file and then Create new file to go to the page for creating a file.

    Figure 6 Opening the page for creating a file

  11. Copy the .github/workflows/ci.yml path and paste it to the file name text box. The ci.yml file is automatically created in the .github/workflows/ directory.

    Figure 7 Creating the ci.yml file

  12. Paste the content copied and saved in 4 to the ci.yml file. When you commit code from the local PC to the develop branch, the code repository url-link-extractor automatically triggers the pipeline.

    name: Build
    on:
      push:
        branches:
          - main
          - develop
      pull_request:
        types: [opened, synchronize, reopened]
    jobs:
      sonarqube:
        name: SonarQube
        runs-on: windows-latest
        steps:
          - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
            with:
              fetch-depth: 0  # Shallow clones should be disabled for a better relevancy of analysis
          - name: SonarQube Scan
            uses: SonarSource/sonarqube-scan-action@7006c4492b2e0ee0f816d36501671557c97f5995 # v8.1.0
            env:
              SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

    Note that code in this practice is developed based on the develop branch. It is expected that the code is also scanned when the develop branch is pushed. Therefore, the - develop value is added under branches.

  13. After pasting the content, click Commit changes in the upper right corner.
  14. Click Add file and then Create new file to go to the page for creating a file.

    Figure 8 Opening the page for creating a file

  15. Switch to the develop branch. In the root directory, paste the content of point 3 in 4 to the new file name and content, click Commit changes twice. The Code page is automatically displayed.

    Figure 9 Point 3 of Project onboarding
    Figure 10 Creating a sonar-project.properties file