Hands on DevOps Coaching provided on AWS and Azure Cloud platforms. please contact at devops.coaching@gmail.com for more info. You can also directly reach out to Coach AK at +1(469) 733-5248
Once added SonarQube plug-in, click on proceed to Organization..
How to integrate SonarQube with Azure DevOps:
Create Token in SonarQube to authenticate with Azure DevOps
You need to login to SonarQube using your admin password. admin/admin123 and click on Admin on your top side.
Click on My Account, Security.
Under Tokens, Give some value for token name and choose Global analysis token, click on generate Tokens. Copy the token value generated.
Create Service Connections in Azure DevOps
Login to Azure DevOps. Select your project dashboard.
Click on Project settings --> Service connections
click on New service connection
Type SonarQube and Click Next
Enter SonarQube server url and enter Token created
Give name for service connection and select Grant access permission to all pipelines.
Click on Save.
Create a YAML Pipeline in Azure DevOps
1. Login to Azure DevOps. Go to Azure Pipelines. Click on create a new pipeline, Select GitHub:
2. Select your GitHub repo and select the Maven as YAML pipeline template
3. Click on show assistant on right hand side, type SonarQube and select Prepare Analysis on SonarQube task and then select Service connection from the drop down and choose Integrate with Maven or Gradle option and then click on Add task
Sample Code for entire pipeline is here below
Azure DevOps Pipeline YAML Code:
# Maven
# Build your Java project and run tests with Apache Maven.
# Add steps that analyze code, save build artifacts, deploy, and more:
Terraform is an open source infrastructure as code (IaC) tool developed by HashiCorp. It allows you to define, manage, and provision infrastructure resources in a cloud or on-premises environment using declarative configuration files. Terraform maintains the state of the infrastructure in a state file.
Please find the steps for installing Terraform On Ubuntu 24.0.4 in AWS cloud.
How to create Ubuntu 24.0.4 EC2 instance in AWS console?
What is EC2 instance?
It is virtual server provided by AWS. EC2 instances can be used to setup both Jenkins and Tomcat. Please follow the below steps to create an EC2 instance.
click on All services, Click on Compute --> Click on EC2
2. Click on Launch instance
3. Enter Name as EC2 and enter 2 as number of instances (one for Jenkins and another for Tomcat)
4. Select Ubuntu
5. choose Ubuntu server 24.0.4 as AMI
6. Enter t2.small as instance type
7. Click on Create new Key Pair
8. Choose the existing key pair if you have one already from the drop down, otherwise create new one, give some name as myEC2Key. Make sure you download the key in your local machine.Please do NOT give space or any character while naming the key.
9. Under Network settings, Click Edit
Add port range as 8080 and select AnyWhere as Source Type, that should enter 0.0.0.0/0 as Source
10. Enter 10 GB as storage
And then make sure in Summary, values appear as below:
11. Click on Launch Instance.
Click on View instances
Now you should be able to view instances in AWS console. Now you can re-name as Jenkins-EC2 and Tomcat-EC2
Watch Steps in YouTube channel:
Connect to EC2 instance from local machine: Please click the below link to understand the steps for connecting to EC2 instance from your local machine - windows or Apple laptop.
Ansible is an open-source, configuration management tool that automates cloud provisioning, configuration management, and application deployments.
Ansible Playbooks
Ansible playbooksallow you to direct Ansible to configure your environment. Playbooks are coded using YAML so as to be human-readable.
Watch steps in YouTube channel:
Automate Azure Web App setup using Ansible and Azure pipeline
Integrate Ansible with Azure Cloud
Integrating Ansible with Microsoft Azure allows you to automate and manage your Azure infrastructure using Ansible playbooks and modules. Ansible provides a collection of Azure-specific modules that enable you to provision and configure resources in Azure.
To configure Azure credentials, you need the following information:
Your Azure subscription ID and tenant ID
The service principal application ID and secret
Pre-requisites:
Azure account subscription, click here if you don't have one.
Run the following commands to create an Azure Service Principal:
az ad sp create-for-rbac --name ansible-azure-sp --role Contributor --scopes /subscriptions/<subscription_id>
Save the above output in a file as you will not be able retrieve later.
Create an Ansible playbook - create-linux-app-svc.yml
Create a simple playbook to create resource group in Azure and also a Azure App Service. Make sure you modify the name of the resource group, Azure WebApp and location below.
- hosts: localhost
connection: local
vars:
resource_group: myResourceGroup
webapp_name: myfirstAwesomeWebApp
plan_name: myAppServicePlan
location: eastus
tasks:
- name: Ensure resource group exists
azure_rm_resourcegroup:
name: myResourceGroup
location: East US
register: rg_result
- debug:
var: rg_result
- name: Create App Service on Linux with Java Runtime
Let's say that you have configured Jenkins in AWS EC2 instance and you are using AWS free tier and you are NOT using Elastic IP, so when ever you start EC2 instance after stopping, you would have noticed Jenkins UI is taking a lot of time to come up. You try to access any page in Jenkins, it will be really slow.
What is the root cause of the issue?
Because EC2 configured in AWS free tier account would have new IP after every restart, Jenkins was trying to use old IP address when you are trying to start Jenkins. Due to this issue, Jenkins will be very slow.
Pre-requisites:
Jenkins is setup in AWS cloud using free-tier account.
There are two ways you can fix this issue:
First option using command line
Make changes in the xml file by logging into EC2 instance through command line using Git bash or any SSH tool.
Connect to Jenkins EC2 instance using Git bash or iTerm:
Navigate to Jenkins installation directory:
cd /var/lib/jenkins/
Modify jenkins.model.JenkinsLocationConfiguration.xml file by executing below command:
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.