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

Friday, February 20, 2026

How to Integrate SonarQube Cloud with Jenkins | Jenkins SonarQube Cloud Integration | Automate Static Code Quality Analysis with SonarQube Cloud from Jenkins

Automate Static Code Quality Analysis with SonarCloud from Jenkins



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 Jenkins:
  • SonarQube plug-in - Make sure this plug-in is installed.
  • pipeline stage view plug-in

    After setting up SonarCloud successfully, login to Jenkins. Manage Jenkins --> Configure System --> SonarQube installation 

    Server URL should be https://sonarcloud.io/
    Enter Sonar token as secret text and select it from the drop down

     
    Jenkins Pipeline code for running scan in SonarCloud

    node {

        def mvnHome = tool 'Maven3'
        stage ("checkout")  {
            git branch: 'main', credentialsId: '', url: 'https://github.com/akannan1087/my-javawebapp-repo'
        }

       stage ('build')  {
        sh "${mvnHome}/bin/mvn clean install -f MyWebApp/pom.xml"
        }

         stage ('Code Quality scan')  {
           withSonarQubeEnv('SonarCloud') {
                sh """
                  ${mvnHome}/bin/mvn -f MyWebApp/pom.xml \
                 org.sonarsource.scanner.maven:sonar-maven-plugin:4.0.0.4121:sonar \
                  -Dsonar.organization=org_key \
                  -Dsonar.projectKey=com.dept.app:MyWebApp \
                  -Dsonar.projectName=MyWebApp
                """
            }
       }
    }

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


    Here is the pipeline view:

    Watch steps in YouTube Video:

    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

      Friday, January 24, 2025

      How to create Pull Request (PR) templates in Azure Repos? | Creating pull request template in Azure Repos


      Watch steps in YouTube channel:

      Azure Repos allows you to create Pull Request (PR) templates to standardize and streamline the PR process for your team. This ensures that all necessary information is included, making the review process more efficient. 

      Step-by-Step Guide

      1. Navigate to Your Repository:

        • Go to the Azure Repos repository where you want to create a PR template.
      2. Create a .azuredevops Directory:

        • create a new directory named .azuredevops in the root of your repository. This is where Azure Repos looks for configuration files, including PR templates.
      3. Create a PULL_REQUEST_TEMPLATE File:

        • Inside the .azuredevops directory, create a file named PULL_REQUEST_TEMPLATE.md. This file will contain the template for your pull requests.

            4. Add Template Content:

      • Open the PULL_REQUEST_TEMPLATE.md file and add the content you want to include in your PR template. You can use Markdown to format the template. Here’s an example of a basic PR template:

      ## What type of PR is this? (check all applicable)
      - [ ] 🍕 New Feature
      - [ ] 🎨 Enhancment Feature
      - [ ] 🐛 Bug
      ## Describe about your code changes
      <!-- 
      Please do not leave this blank 
      This PR [adds/removes/fixes/replaces] the [feature/bug/etc]. 
      -->
      ## Related Feature & Documents
      <!-- 
      Please use this format link issue numbers: Fixes #123
      -->
      ## Screenshots/Recordings Link In Sharepoint
      <!-- Visual changes require screenshots -->

      ## Created Unit tests, etc?
      - [ ] 👍 yes
      - [ ] 🙅 no, because they aren't needed
      - [ ] 🙋 no, because I need help
      ## Added to documentation?
      - [ ] 📜 README.md
      - [ ] 📕 wiki
      - [ ] 🙅 no documentation needed
      ## [optional] Are there any post-deployment tasks we need to perform?

          5. Commit and Push:

      • Commit the PULL_REQUEST_TEMPLATE.md file to your repository and push it to Azure Repo.

      git add .azuredevops/PULL_REQUEST_TEMPLATE.md 
      git commit -m "Add pull request template" 
      git push origin main


      Sunday, November 17, 2024

      How to Configure GitHub Advanced Security for Azure DevOps | How to Perform Security scan for Azure Repos using GitHub Advanced Security

      GitHub Advanced Security for Azure DevOps brings the secret scanning, dependency scanning and CodeQL code scanning solutions already available for GitHub users and natively integrates them into Azure DevOps to protect your Azure Repos and Pipelines. 


      Pre-requisites:

      How to Set up dependency scanning?

      Dependency scanning is a pipeline-based scanning tool. Results are aggregated per repository. It's recommended that you add the dependency scanning task to all the pipelines you'd like to be scanned.

      Add the task Advanced Security Dependency Scanning task (AdvancedSecurity-Dependency-Scanning@1) directly to your YAML pipeline file or select the Advanced Security Dependency Scanning task from the task assistant.

      How to Set up code scanning

      Code scanning is also a pipeline-based scanning tool where results are aggregated per repository.

      Add the tasks in the following order:

      1. Advanced Security Initialize CodeQL (AdvancedSecurity-Codeql-Init@1)
      2. Your custom build steps
      3. Advanced Security Perform CodeQL Analysis (AdvancedSecurity-Codeql-Analyze@1)
      Pipeline YAML Code for scanning Java code using GitHub Advanced Security

      Create a Pipeline:
      Login to your Azure Devops dashboard https://dev.azure.com


      Go to Pipelines, Click New, 
      select your SCM.


      Select your Repository. Use starter pipeline and copy and paste the below code:


      trigger:
      - main

      resources:
      - repo: self

      variables:
      tag: '$(Build.BuildId)'

      stages:
      - stage: Build
      displayName: Build image
      jobs:
      - job: Build
      displayName: Build
      pool:
      vmImage: ubuntu-latest
      steps:
      - task: AdvancedSecurity-Codeql-Init@1
      inputs:
      languages: 'java'
      - task: Maven@4
      inputs:
      mavenPomFile: 'pom.xml'
      goals: 'install'
      publishJUnitResults: true
      testResultsFiles: '**/surefire-reports/TEST-*.xml'
      javaHomeOption: 'JDKVersion'
      mavenVersionOption: 'Default'
      mavenAuthenticateFeed: false
      effectivePomSkip: false
      sonarQubeRunAnalysis: false
      - task: AdvancedSecurity-Dependency-Scanning@1
      - task: AdvancedSecurity-Codeql-Analyze@1

      Where to see the Scan resule in Azure DevOps?


      Monday, November 4, 2024

      What is GitHub Advanced Security for Azure DevOps | How to Enable GitHub Advanced Security for Azure DevOps ?

      GitHub Advanced Security for Azure DevOps brings the secret scanning, dependency scanning and CodeQL code scanning solutions already available for GitHub users and natively integrates them into Azure DevOps to protect your Azure Repos and Pipelines.


      These scanning tools will natively embed automated security checks into the Azure DevOps platform, allowing developers to secure their code, secrets and supply chain without leaving their workflow.

      Azure DevOps Advanced Security provides below security features to help organizations identify and address security vulnerabilities in their development processes.

      • Secret Scanning push protection: check if code pushes include commits that expose secrets such as credentials
      • Secret Scanning on repos: scan your repository and look for exposed secrets that were committed accidentally
      • Dependency Scanning – search for known vulnerabilities in open source dependencies (direct and transitive)
      • Code Scanning – use CodeQL static analysis engine to identify code-level application vulnerabilities such as SQL injection and authentication bypass.
      Scope of GitHub Advanced Security for Azure DevOps
      • only available for Git repositories
      • only available for Azure DevOps services, not available in Azure DevOps Server(old TFS) 

      Pre-requisites:

      Enable GitHub Advanced Security
      You can enable Advanced Security at the organization, project, or repository level.

      Organization-level onboarding
      1. Go to your Organization settings for your Azure DevOps organization.
      2. Select Repositories.
      3. Select Enable all and see an estimate for the number of active committers for your organization appear.
      4. Select Begin billing to activate Advanced Security for every existing repository in each project in your organization.
      5. Optionally, select Automatically enable Advanced Security for new repositories so that any newly created projects have Advanced Security enabled upon creation.

      Project-level onboarding

      1. Go to your Project settings for your Azure DevOps project.
      2. Select Repos.
      3. Select the Settings tab.
      4. Select Enable all and see an estimate for the number of active committers for your project appear.
      5. Select Begin billing to activate Advanced Security for every existing repository in your project.
      6. Optionally, select Automatically enable Advanced Security for new repositories so that any newly created repositories have Advanced Security enabled upon creation.
      Repository-level onboarding
      1. Go to your Project settings for your Azure DevOps project.
      2. Select Repos > Repositories.
      3. Select the repository you want to enable Advanced Security for.
      4. Select Enable and Begin billing to activate Advanced Security. A shield icon now appears in the repository view for any repository with Advanced Security enabled.


      Setup Secret Scanning
      Secret scanning push protection and repository scanning are automatically enabled when you turn on Advanced Security. You can enable or disable secret push protection from the repository settings page.

      Screenshot of enabling push protection.

      As mentioned, secret scanning repository scanning is automatically kicked off upon enabling Advanced Security for a selected repository.

      Friday, June 7, 2024

      How to create Pull Request (PR) templates in Github repository | Creating a pull request template for your GitHub repository


      Creating pull request (PR) templates in GitHub can help streamline the process of submitting PRs by providing a predefined structure. This ensures that all necessary information is included, making the review process more efficient. 

      Step-by-Step Guide

      1. Navigate to Your Repository:

        • Go to the GitHub repository where you want to create a PR template.
      2. Create a .github Directory:

        • If it doesn't already exist, create a new directory named .github in the root of your repository. This is where GitHub looks for configuration files, including PR templates.
      3. Create a PULL_REQUEST_TEMPLATE File:

        • Inside the .github directory, create a file named PULL_REQUEST_TEMPLATE.md. This file will contain the template for your pull requests.

            4. Add Template Content:

      • Open the PULL_REQUEST_TEMPLATE.md file and add the content you want to include in your PR template. You can use Markdown to format the template. Here’s an example of a basic PR template:

      ## What type of PR is this? (check all applicable)
      - [ ] 🍕 New Feature
      - [ ] 🎨 Enhancment Feature
      - [ ] 🐛 Bug
      ## Describe about your code changes
      <!-- 
      Please do not leave this blank 
      This PR [adds/removes/fixes/replaces] the [feature/bug/etc]. 
      -->
      ## Related Feature & Documents
      <!-- 
      Please use this format link issue numbers: Fixes #123
      -->
      ## Screenshots/Recordings Link In Sharepoint
      <!-- Visual changes require screenshots -->

      ## Created Unit tests, etc?
      - [ ] 👍 yes
      - [ ] 🙅 no, because they aren't needed
      - [ ] 🙋 no, because I need help
      ## Added to documentation?
      - [ ] 📜 README.md
      - [ ] 📕 wiki
      - [ ] 🙅 no documentation needed
      ## [optional] Are there any post-deployment tasks we need to perform?

          5. Commit and Push:

      • Commit the PULL_REQUEST_TEMPLATE.md file to your repository and push it to GitHub.

      git add .github/PULL_REQUEST_TEMPLATE.md 
      git commit -m "Add pull request template" 
      git push origin main

      Optional: Multiple Templates

      If you want to offer multiple PR templates, you can place them in the .github/PULL_REQUEST_TEMPLATE/ directory. Each template should be a separate Markdown file.

      Using PR templates helps maintain consistency and completeness in pull requests, making it easier for reviewers to understand and review changes. Adjust the templates according to the needs and standards of your project.

      Watch steps in YouTube channel:

      Monday, March 4, 2024

      How to Integrate Slack with GitHub Actions | Slack Integration with GitHub Actions| Send Push notifications to Slack GitHub Actions

      Integrating Slack with GitHub Actions for sending Notifications



      Pre-requisites:

      How to integrate Slack with GitHub Actions:

      We will be using slack GitHub Action Slack integration action for posting messages to Slack channel from GitHub Actions.

      We will be following below steps:

      1. Create a new App in https://api.slack.com/apps
      2. Select workspace in the app
      3.Select incoming webhooks
      4. Activate incoming webhook
      5. Add new webhook integration
      6. Select channel, Allow
      7. Copy the webhook url

      Create App from scratch


      Enter App name and pick a workspace
      Click on incoming webhooks
      Activate incoming webhooks, click on Add new webhook to workspace

      Select the channel where you want to send notfications

      Copy webhook url



      Add Slack Webhook 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
      Add SLACK_WEBHOOK_URL with value


      Create GitHub Actions CICD workflow yaml:

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

      .github/workflows/cicd.yml


      name: cicd-workflow with slack integration
      on:
        push:
          branches:
            - main
        workflow_dispatch:
      jobs:
        build:
          runs-on: ubuntu-latest
          env:
            SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
          steps:
          - uses: actions/checkout@v3
          - name: Set up JDK 11
            uses: actions/setup-java@v2
            with:
              distribution: 'adopt'
              java-version: '11'
          - name: Build with Maven
            run: mvn install -f MyWebApp/pom.xml
          - uses: act10ns/slack@v2
            with:
              channel: '#mar-2024-weekday-batch'
              status: ${{ job.status }}
              steps: ${{ toJson(steps) }}
            if: always()


      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