devops_batch2_all_experiments
devops_batch2_all_experiments
Maven
**Aim:** To establish an automated software build pipeline using Maven in Azure DevOps, enabling
efficient and continuous integration of code changes.
**Prerequisites:**
- Azure DevOps account with access to Azure Pipelines
- Source code repository containing a Maven project
- Basic understanding of Maven build lifecycle
- Permissions to create and manage pipelines
**Procedure:**
1. Sign in to Azure DevOps and create a new project if one doesn't exist.
2. Navigate to Repos and push your Maven project code to Azure Repos Git.
3. Click on Pipelines > New Pipeline.
4. Select the repository containing the Maven project.
5. Choose "Starter pipeline" or existing YAML template.
6. Modify the YAML with Maven tasks as below:
```
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Maven@3
inputs:
mavenPomFile: 'pom.xml'
goals: 'clean install'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
```
7. Save and run the pipeline to verify it compiles and packages successfully.
**Output:** A running pipeline that compiles code, runs tests, and generates reports on each push to
the main branch.
**Result:** An automated build pipeline is successfully established in Azure DevOps using Maven.
Experiment 2: End-to-end Maven build pipeline with regression testing in Azure
DevOps
**Aim:** To develop an Azure DevOps Maven pipeline that includes regression testing for ensuring
code quality during each build.
**Prerequisites:**
- Azure DevOps setup with permissions
- Maven project with integrated regression test suite (JUnit/TestNG)
- Prepared test data if needed
**Procedure:**
1. Push your Maven project to Azure Repos.
2. Include a robust regression test suite in the test folder.
3. In Azure Pipelines, create a pipeline using the YAML configuration.
4. Add tasks for compiling, executing tests, and publishing results:
```
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Maven@3
inputs:
goals: 'clean verify'
- task: PublishTestResults@2
inputs:
testResultsFiles: '**/target/surefire-reports/TEST-*.xml'
```
5. Configure the test environment via pipeline variables and service connections.
6. Use pipeline extensions for better test visualization (e.g., Test Plans).
**Output:** Comprehensive test results including regressions are published, and detailed reports are
accessible in the Azure DevOps dashboard.
**Result:** A complete Maven build pipeline with regression testing is implemented, supporting high
software quality assurance.
Experiment 3: Create CI pipeline using Jenkins
**Aim:** To create a Jenkins-based Continuous Integration (CI) pipeline to automatically build, test,
and report application changes.
**Prerequisites:**
- Jenkins installed and configured with necessary plugins
- Git repository URL of your application
- Maven or Gradle installed on Jenkins agents
**Procedure:**
1. Open Jenkins and create a new Pipeline project.
2. Configure the SCM section with your Git repository.
3. Write a Jenkinsfile (declarative pipeline) to automate CI:
```
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git 'https://github.com/user/repo.git'
}
}
stage('Build') {
steps {
sh 'mvn clean install'
}
}
stage('Test') {
steps {
sh 'mvn test'
}
}
}
}
```
**Result:** CI pipeline in Jenkins facilitates early error detection and rapid feedback.
Experiment 4: Create a CD pipeline in Jenkins and deploy in Cloud
**Prerequisites:**
- Jenkins with required plugins (SSH, cloud CLI tools)
- Maven/Gradle project and cloud credentials (e.g., AWS IAM, Azure Service Principal)
**Procedure:**
1. Create a Jenkins Pipeline project.
2. Write a Jenkinsfile to build and deploy your application:
```
pipeline {
agent any
environment {
CLOUD_CREDENTIALS = credentials('cloud-creds-id')
}
stages {
stage('Build') {
steps {
sh 'mvn package'
}
}
stage('Deploy') {
steps {
sh 'scp target/app.war user@cloudhost:/var/www/'
sh 'ssh user@cloudhost "sudo systemctl restart tomcat"'
}
}
}
}
```
3. Configure credentials securely in Jenkins.
**Output:** Application is built and deployed to the cloud after successful build.
**Aim:** To build a simple Java application using Gradle as the build tool, managing dependencies
and tasks efficiently.
**Prerequisites:**
- JDK and Gradle installed
**Procedure:**
1. Create a project using:
```
gradle init --type java-application
```
2. Modify build.gradle to add dependencies:
```
dependencies {
implementation 'com.google.guava:guava:30.1-jre'
testImplementation 'junit:junit:4.13.2'
}
```
**Prerequisites:**
- Jenkins setup
- Deployment server/cloud instance
- SSH access or cloud CLI configured
**Procedure:**
1. Configure pipeline to include build and deploy stages.
2. Use SCP/SSH or cloud CLI to deploy to instance.
3. Use Jenkins credentials manager for secrets.
**Prerequisites:**
- Jenkins configured with agents
- Build tool (Maven/Gradle) installed
**Procedure:**
1. Define stages for build, testing, packaging, and deployment.
2. Use post-build actions to trigger cloud deployments.
3. Ensure rollback steps in case of failure.
**Aim:** To explore key considerations when deploying applications using Jenkins CD pipelines in
cloud environments.
**Prerequisites:**
- Basic cloud and Jenkins knowledge
**Procedure:**
1. Secure secrets using credential vaults.
2. Ensure CI validation before deployment.
3. Implement health checks post-deployment.
4. Monitor application logs and metrics.
5. Use immutable artifacts and infrastructure as code.
**Aim:** To create a robust Jenkins CD pipeline that automates build, test, package, and deploy
stages using cloud services.
**Prerequisites:**
- Jenkins, cloud CLI (Azure/AWS), Maven
**Procedure:**
1. Write Jenkinsfile with sequential stages:
```
pipeline {
agent any
stages {
stage('Build') { steps { sh 'mvn clean install' } }
stage('Test') { steps { sh 'mvn test' } }
stage('Package') { steps { sh 'mvn package' } }
stage('Deploy') {
steps {
sh 'az webapp deploy --name myapp --src-path target/app.war'
}
}
}
}
```
**Prerequisites:**
- Ansible installed
- Basic YAML understanding
**Procedure:**
1. Use modular roles and reusable variables.
2. Maintain consistent formatting and comments.
3. Use handlers and conditionals effectively.
4. Maintain idempotency in all tasks.
**Aim:** To use regression testing outputs for improving software reliability in Azure DevOps.
**Prerequisites:**
- Test suites with meaningful coverage
- Azure Pipelines test reporting enabled
**Procedure:**
1. Execute regression tests via Maven.
2. Collect results using PublishTestResults.
3. Set quality gates or approval steps based on test results.
4. Trigger alerts for failures or anomalies.
**Result:** Regression tests enable proactive bug detection and quality improvements.
Experiment 12: Ansible playbook for web app setup
**Aim:** To automate the deployment and configuration of a web application using Ansible.
**Prerequisites:**
- Ansible and target host configured with SSH access
**Procedure:**
1. Create inventory file defining web hosts.
2. Write playbook:
```
- hosts: webservers
become: yes
tasks:
- name: Install Apache
apt:
name: apache2
state: present
```
ansible-playbook -i inventory webapp.yml
```