Friday, February 20, 2026

How to Integrate SonarQube Cloud with GitHub Actions | GitHub Actions SonarQube Cloud Integration | Automate Static Code Quality Analysis with SonarQube Cloud from GitHub Action

 Automate Static Code Quality Analysis in SonarQube Cloud from GitHub Actions:



Pre-requisites in SonarCloud:




Depending on your SCM tool, We will use GitHub. So please click on it.
Enter GitHub credentials to setup your account in SonarCloud. Click Authorize SonarQube Cloud.


Go to SonarCloud → My Account → Organizations → Create/Select organization

Choose “Import from GitHub” (or connect GitHub) and Install the SonarCloud GitHub App

Start analyzing a project:

Select Project and Click on Setup:


Check any one of the options to confirm what is new code:

Select with other CI tools





Select Maven, note organization key, project key and token.

Pre-requisites in GitHub Actions:

    After setting up SonarCloud successfully, login to GitHub Actions. 
    Create two secrets SONAR_TOKEN and SONAR_HOST_URL
    Sonar URL should be https://sonarcloud.io/
     
    GitHub Actions CICD Workflw code for running scan in SonarCloud

    name: Implement static code analysis for a Java App using SonarQube from GitHub Actions
    on:
      push:
        branches:
          - main
      workflow_dispatch:
    jobs:
     build:
      runs-on: ubuntu-latest
      steps:
      - name: checkout code
        uses: actions/checkout@v3
      - name: Set up JDK
        uses: actions/setup-java@v3
        with:
          distribution: 'adopt'
          java-version: '11'
      - name: Build with Maven
        run: mvn clean install -f MyWebApp/pom.xml
      - name: Run SonarQube Scan
        uses: sonarsource/sonarqube-scan-action@master
        with:
          projectBaseDir: .
          args: >
            -Dsonar.organization=akannan1087
            -Dsonar.projectKey=akannan1087_my-javawebapp-repo
            -Dsonar.java.binaries=**/target/classes
        env:
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
          SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}

    Now login to SonarCloud under --> https://sonarcloud.io/projects


    Watch steps in YouTube channel:

    No comments:

    Post a Comment

    Coach AK's Master DevSecOps Bootcamp Program Model Information | Master Multi cloud Program Information | AWS Cloud and Azure Cloud DevOps Coaching Program Model Information

    (More New Topics..New tools added such as GitHub Actions, Helm, GitHub Advanced Security and Trivy Scanner, CheckOv IAC security ...