Showing posts with label GitHub Actions. Show all posts
Showing posts with label GitHub Actions. Show all posts

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 17
        uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: '17'
          cache: 'maven'
      - 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:

    Saturday, March 8, 2025

    How to Implement CICD Pipeline using GitHub Actions | GitHub Actions Tutorials | GitHub Actions CICD Pipeline | How to Deploy Java WAR file using GitHub Actions and Maven to Tomcat Server

    Please find steps for Deploying Java WAR file to Tomcat using GitHub Actions:

    Watch GitHub Actions CICD in YouTube:

      Pre-requisites:

      Implementation steps:

      We need to setup secrets to store tomcat user name, password and Tomcat url.

      Add Tomcat user name, password and Tomcat Host url as Secret in GitHub Actions

      Go to your GitHub Repo --> Settings --> 

      Click on Secrets and Variables under Security in left nav 
      Click new Repository Secret

      Create TOMCAT_HOST secret and add tomcat url

      Create TOMCAT_USER secret and add user name
      Create TOMCAT_PASSWORD secret and Tomcat password


      GitHub Actions Workflow YAML for Deploying a WAR file to Tomcat

      You will create this file .github/workflows/cicd.yaml inside GitHub Repo where your Java code is.

      name: Build a WAR file using Maven and Deploy Java App to Tomcat running in AWS EC2
      on:
        push:
          branches: [ "main" ]
      jobs:
        build:
          runs-on: ubuntu-latest
          steps:
          - uses: actions/checkout@v3
          - name: Set up JDK 17
            uses: actions/setup-java@v4
            with:
              distribution: 'temurin'
              java-version: '17'
              cache: 'maven'
          - name: Build with Maven
            run: mvn clean install -f MyWebApp/pom.xml
          - name: Deploy to Tomcat
            run: |
              curl -v -u ${{ secrets.TOMCAT_USER }}:${{ secrets.TOMCAT_PASSWORD }} \
              -T MyWebApp/target/MyWebApp.war \
              "http://${{ secrets.TOMCAT_HOST }}/manager/text/deploy?path=/MyWebApp&update=true"

      Commit the file.

      As soon as you commit, build will run immediately in GitHub Actions. 
      Now you can see the output of build in Actions tab.

      Check the output in Tomcat

      Thursday, April 18, 2024

      GitHub Actions CICD Pipeline to Deploy Java WebApp into Azure App Service | Integration GitHub Actions with Azure App Service


      Pre-requisites:

      What are we going to do in this lab?
      1. Create a Web App in Azure Cloud
      2. Configure WebApp to Deploy using gitHub Actions
      3. Create workflow yaml
      4. Add steps/tasks in the yaml file
      5. Run the workflow yaml
      6. Check if Java Web App is deployed in Azure App Service

      How to Create WebApp in Azure Portal?

      1. Login portal.azure.com
      2. Click on App services


      3.Click on + Add or click on Create app service


      Click on Web App. Choose your Azure subscription, usually Pay as you Go or Free trial subscription
      Create a new resource group or you can use existing resource group)


      Enter App service name(it should be unique)
      Publish as Code
      Run time stack as Java 17
      Java Web Server stack --> Tomcat 10.0
      Operating System as Linux
      Region as Central US or where ever you are based at

      Enter LinuxPlan name
      Choose pricing plan

      Now go to Deployment tab:
      Enable basic authentication
      and enable Continuous Deployment 


      Click on GitHub account, Authorize.
      Authorize AzureappService
      now select organization, repo, branch



      You can also click on preview file to get pipeline YAML code 

      Click on Review and Create




      Create Web App
      Now make sure AzureAppService_PublishProfile secret is automatically created in GitHub repo you selected.



      Create GitHub Actions CICD workflow yaml:

      name: Build and deploy WAR app to Azure Web App
      on:
        push:
          branches:
            - main
        workflow_dispatch:
      jobs:
        build:
          runs-on: ubuntu-latest
          steps:
            - uses: actions/checkout@v4
            - name: Set up Java version
              uses: actions/setup-java@v2
              with:
                java-version: '11'
                distribution: 'adopt'
            - name: Build with Maven
              run: mvn clean install -f MyWebApp/pom.xml
            - name: Upload artifact for deployment job
              uses: actions/upload-artifact@v3
              with:
                name: MyWebApp
                path: '${{ github.workspace }}'
        deploy:
          runs-on: ubuntu-latest
          needs: build
          environment:
            name: 'Production'
            url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
          steps:
            - name: Download artifact from build job
              uses: actions/download-artifact@v3
              with:
                name: MyWebApp
            - name: Deploy to Azure Web App
              id: deploy-to-webapp
              uses: azure/webapps-deploy@v2
              with:
                app-name: 'spingbootwebapp'
                slot-name: 'Production'
                publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_76B948D486E54ED7B06775D572207D40 }}
                package: '*.war'


      Check the output after running the pipeline:


      Verify if WebApp has been deployed into Azure App Service by browsing Web App url.

      https://mysuperjavaapp.azurewebsites.net/MyWebApp/

      Watch here all the steps in YouTube channel:

      Saturday, April 6, 2024

      GitHub Actions CICD Pipeline to Create Docker Image and Push Docker Image into Amazon ECR | Integrate GitHub Actions with AWS ECR

      Please find steps for integrating AWS ECR with GitHub Actions:


      Pre-requisites:

      What are we going to do in this lab?
      1. Create a Repository in AWS ECR
      2. Create AWS secret keys + access keys
      3. Create secrets in GitHub Actions
      4. Create workflow yaml
      5. Add steps/tasks in the yaml file
      6. Run the workflow yaml
      7. Check if docker image is been stored in AWS ECR

      How to Create a repo in ECR ?

      Go to AWS console and search for ECR

      Click on Create Repository



      Enter name for your repo - all lower case and Click create repository


      Once repo is created, choose the repo and click on view push commands. Note down the account ID


      Add Access keys and Secret keys as Secrets in GitHub Actions

      Go to your GitHub Repo --> Settings --> 

      Click on Secrets and Variables under Security in left nav 
      Click new Repository Secret


      Create secrets in GitHub for AWS_REGION,  REPO_NAME,  AWS_SECRET_ACCESS_KEY and AWS_ACCESS_KEY_ID

      Create GitHub Actions CICD workflow yaml:

      Go to GitHub repo where your Java project is, create a new file:

      .github/workflows/cicd.yml


      The below file have four steps(tasks) 
          - Checkout
          - Install Java on runner
          - Build springboot Jar file using Maven
          - Build docker image and tag it
          - Upload docker image into AWS ECR

      Copy the content from below:
      name: cicd-workflow to create docker image and upload into AWS ECR
      on:
        push:
          branches: [ "master" ]
      jobs:
        job1:
          runs-on: ubuntu-latest
          steps:
          - uses: actions/checkout@v3
          - name: Set up JDK 17
            uses: actions/setup-java@v2
            with:
              distribution: 'adopt'
              java-version: '17'
          - name: Build with Maven
            run: mvn clean install
          - name: Setup AWS ECR Details
            uses: aws-actions/configure-aws-credentials@v1
            with:
              aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
              aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
              aws-region: ${{secrets.AWS_REGION}}
          - name: Login to Amazon ECR
            id: login-pf-aws-ecr
            uses: aws-actions/amazon-ecr-login@v1
          - name: Build and push Docker image
            env:
              ECR_REGISTRY: ${{ steps.login-pf-aws-ecr.outputs.registry }}
              ECR_REPOSITORY: ${{secrets.REPO_NAME}}
              IMAGE_TAG: ${{ github.sha }}
            run: |
              docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
              docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

      Commit the file.

      As soon as you commit, build will run immediately in GitHub Actions. 
      Now you can see the output of build in Actions tab.


      Please login to AWS console --> ECR and verify if image have been uploaded successfully.


      Watch Steps in YouTube channel:

      GitHub Actions Pipeline to Create Docker Image and Push Docker Image into DockerHub | GitHub Actions Integration with DockerHub

       Please find steps for integrating DockerHub with GitHub Actions:


      Implementation steps:

      • Create access token in DockerHub
      • Add access token, docker hub user name as secrets in GitHub Actions
      • Create GitHub Actions workflow yaml in your repo
      • Add tasks for Maven build, docker image creation, tagging and docker push 
      • Run the workflow/build in GitHub hosted runner(e.g. Ubuntu)
      • Verify docker image have been uploaded into DockerHub

      Pre-requisites:

      Steps below to create access token in DockerHub:

      Click on new access token:
          Copy on Generate

       

      Add Docker Hub user name and token as Secrets in GitHub Actions

      Go to your GitHub Repo --> Settings --> 

      Click on Secrets and Variables under Security in left nav 
      Click new Repository Secret


      Enter DOCKERHUB_USERNAME as secret name and 
      Enter your docker hub user name


      Enter DOCKERHUB_TOKEN as secret name and 
      Enter your token as secret



      Create GitHub Actions CICD workflow yaml:

      Go to GitHub repo where your Java project is, create a new file:

      .github/workflows/cicd.yml


      The below file have four steps(tasks) 
          - Checkout
          - Install Java on runner
          - Build using Maven
          - Build docker image and tag it
          - Upload docker image into DockerHub

      Copy below YAML code:

      name: cicd-workflow to create docker image and upload into Dockerhub
      on:
        push:
          branches: [ "master" ]
      jobs:
        job1:
          runs-on: ubuntu-latest
          steps:
          - uses: actions/checkout@v3
          - name: Set up JDK 17
            uses: actions/setup-java@v2
            with:
              distribution: 'adopt'
              java-version: '17'
          - name: Build with Maven
            run: mvn clean install
          - name: Login to Docker Hub
            uses: docker/login-action@v3
            with:
              username: ${{ secrets.DOCKERHUB_USERNAME }}
              password: ${{ secrets.DOCKERHUB_TOKEN }}
          - name: Build and push Docker image
            env:
              IMAGE_TAG: ${{ github.sha }}
            run: |
              docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/myspringbootapp:${IMAGE_TAG} .
              docker push ${{ secrets.DOCKERHUB_USERNAME }}/myspringbootapp:${IMAGE_TAG}


      Commit the file.

      As soon as you commit, build will run immediately in GitHub Actions. 
      Now you can see the output of build in Actions tab.


      Login to DockerHub to verify if docker image have been uploaded successfully.


      Watch steps in YouTube channel:

      🚀 Live AI-Enabled DevSecOps & Cloud Engineering Bootcamp – Sep 2026

        Live AI-Enabled DevSecOps & Cloud Engineering Bootcamp from Coach AK - Sep 2026 Schedule