DevOps Lab Manual
DevOps Lab Manual
AIM:
To set up a Maven build pipeline in Azure DevOps to automate the build process for a
Maven project.
PROCEDURE:
1. Create a New Project
a. In Azure DevOps:
i. Navigate to Azure DevOps.
ii. Click on "New Project" and fill in the required details.
iii. Click "Create" to initialize the project.
b. In Jenkins (for comparison):
i. Open Jenkins.
ii. Click on "New Item".
iii. Select "Freestyle project" and provide a name like "Maven-Project".
iv. Click "OK" to create the project.
2. Create a New Pipeline
a. In Azure DevOps:
i. Navigate to the project which created.
ii. Click on "Pipelines" in the left sidebar.
iii. Select "New pipeline" to initiate pipeline creation.
b. In Jenkins:
i. Inside the created project, scroll to the "Build" section.
ii. Choose "Add build step".
iii. Select "Invoke top-level Maven targets".
3. Select a Repository
a. In Azure DevOps:
i. Choose the source where the Maven project repository is stored
(Azure Repos Git, GitHub, or another Git service).
ii. Authenticate and select the repository containing the Maven project.
b. In Jenkins:
i. Scroll to the Source Code Management section and select Git.
ii. Enter the repository URL:
https://github.com/MADHAVAN-BE-2003/Maven_Project_1.git
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Maven@3
inputs:
mavenPomFile: 'pom.xml'
goals: 'clean package'
options: '-X'
displayName: 'Run Maven Package'
clean package -X
AIM:
To extend the existing Maven build pipeline to include steps for running regression tests
and reporting results.
PROCEDURE:
1. Update the azure-pipelines.yml File
a. In Azure DevOps:
i. To add regression tests to the Maven pipeline, modify the YAML
configuration to include steps that run tests and publish the results.
Here’s the updated azure-pipelines.yml file:
# azure-pipelines.yml
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Maven@3
inputs:
mavenPomFile: 'pom.xml'
goals: 'clean verify' # Use 'verify' to include tests
options: '-X'
displayName: 'Run Maven Tests'
- task: PublishTestResults@2
inputs:
testResultsFiles: '**/target/surefire-reports/*.xml'
testRunTitle: 'Maven Test Results'
condition: succeededOrFailed()
clean verify
2. Explanation of YAML Configuration
➢ trigger: Specifies the branch that will trigger the pipeline.
➢ pool: Defines the agent pool; ubuntu-latest is commonly used.
➢ steps: Lists the steps of the pipeline.
a. In Azure DevOps:
i. task: Maven@3: Uses the Maven task provided by Azure DevOps.
ii. goals: clean verify: Cleans up previous builds and runs tests (verify
includes both build and test phases).
iii. options: -X: Provides detailed Maven output.
b. In Jenkins:
i. The same goal (clean verify) is specified to execute Maven tests during
the build process.
a. In Azure DevOps:
i. task: PublishTestResults@2: Publishes the results of the tests in Azure
DevOps.
ii. testResultsFiles: Specifies the pattern to locate test result files, typically
found in target/surefire-reports.
iii. testRunTitle: A title for the test run.
iv. condition: succeededOrFailed(): Publishes results even if some tests fail.
b. In Jenkins:
i. Add post-build action by selecting "Publish JUnit test result report".
ii. In the "Test report XMLs" field, enter the path to the test reports,
usually:
**/target/surefire-reports/*.xml
3. Ensure Proper Configuration for Test Reports
a. In Azure DevOps:
i. Ensure the Maven project is configured to produce test reports in a
compatible format. The Maven Surefire Plugin generates XML reports
that Azure DevOps can consume. The pom.xml should contain the
following configuration:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<!-- Ensure this version or newer -->
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
b. In Jenkins:
i. Ensure the Maven Surefire Plugin is configured similarly to generate
reports compatible with Jenkins.
4. Commit Changes and Trigger Pipeline
a. In Azure DevOps (YAML):
i. Save and commit the changes to azure-pipelines.yml in the repository.
ii. Azure DevOps will automatically trigger the pipeline if configured to
do so, or it can be manually run from the Azure DevOps UI.
b. In Jenkins (Manual Configuration):
i. Save the configuration changes in the Jenkins job and click "Build
Now" to run the job.
ii. Ensure that the Jenkins job is set to pull from the repository containing
the updated configuration.
5. Monitor Test Results
a. In Azure DevOps:
i. After the pipeline runs, navigate to the "Pipelines" section.
ii. Click on the pipeline run to view detailed logs and test results.
iii. Go to the "Tests" tab to see the results of the regression tests, including
any failures or errors.
b. In Jenkins:
i. Click on the build number in the "Build History" section to view the
console output.
ii. Check the "Test Results" tab for a summary of the regression tests,
including any failures.
CONSOLE OUTPUT:
[Maven-Project] $ cmd.exe /C "mvn -f pom.xml clean package -X && exit %%ERRORLEVEL%%"
Apache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d260186937)
Maven home: D:\ProgramFiles\Maven\apache-maven-3.9.9
Java version: 17.0.11, vendor: Oracle Corporation, runtime: D:\Program files\Java\jdk-17
Default locale: en_IN, platform encoding: Cp1252
OS name: "windows 11", version: "10.0", arch: "amd64", family: "windows"
[INFO] Scanning for projects...
[INFO] --------------------< com.example.crudapp:crud-app >--------------------
[INFO] Building crud-app 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] --- clean:3.1.0:clean (default-clean) @ crud-app ---
[INFO] Deleting target directory and files...
[INFO] --- resources:3.0.2:resources (default-resources) @ crud-app ---
[INFO] --- compiler:3.8.1:compile (default-compile) @ crud-app ---
[INFO] --- resources:3.0.2:testResources (default-testResources) @ crud-app ---
[INFO] --- compiler:3.8.1:testCompile (default-testCompile) @ crud-app ---
[INFO] --- surefire:2.22.1:test (default-test) @ crud-app ---
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[DEBUG] Determined Maven Process ID 19676
[INFO] Running com.example.crudapp.AppTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.033 s - in
com.example.crudapp.AppTest
[INFO] Results:
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] --- jar:3.0.2:jar (default-jar) @ crud-app ---
[INFO] Building jar: C:\ProgramData\Jenkins\.jenkins\workspace\Maven-Project\target\crud-app-1.0-
SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.502 s
[INFO] Finished at: 2024-11-11T22:39:17+05:30
[INFO] ------------------------------------------------------------------------
AIM:
To install Jenkins in various cloud environments (AWS, Azure, Google Cloud) and on
a local Windows machine to facilitate Continuous Integration (CI) processes.
PROCEDURE:
Install Jenkins on AWS (Amazon Web Services)
4. Access Jenkins
a. Open a web browser and go to http://<your-ec2-public-ip>:8080.
b. Retrieve the Jenkins unlock key:
c. Enter this key in the Jenkins setup wizard to complete the installation.
5. Access Jenkins
a. Open a web browser and go to http://<your-ec2-public-ip>:8080.
b. Retrieve the Jenkins unlock key:
c. Enter this key in the Jenkins setup wizard to complete the installation.
6. Access Jenkins
a. Open a web browser and go to http://<your-ec2-public-ip>:8080.
b. Retrieve the Jenkins unlock key:
1. Install Java
a. Download Java JDK: Go to the Oracle website and download the JDK
installer.
b. Install Java: Run the installer and follow the installation instructions.
c. Set JAVA_HOME Environment Variable:
i. Open Control Panel > System and Security > System > Advanced
system settings > Environment Variables.
ii. Under "System variables", click "New" and add JAVA_HOME with the
path to your JDK installation (e.g., C:\Program Files\Java\jdk-11.0.x).
2. Install Jenkins
a. Download Jenkins: Go to the Jenkins website and download the Windows
installer.
b. Run the Installer: Follow the installation instructions to install Jenkins as a
Windows service.
c. Start Jenkins: Jenkins should start automatically as a service; if not, start it via
the Services management console.
3. Access Jenkins
a. Open a web browser and go to http://localhost:8080.
b. Retrieve the Jenkins unlock key from the specified path (default: C:\Program
Files (x86)\Jenkins\secrets\initialAdminPassword) and enter it in the setup
wizard.
RESULT:
Thus, Jenkins was successfully installed across AWS, Azure, Google Cloud, and a local
Windows environment, enabling automated building, testing, and deployment of code, which
enhances the software development lifecycle's efficiency and reliability.
EXP NO: DATE: ___/___/_____
AIM:
To set up a Continuous Integration (CI) pipeline in Jenkins to automate the build process
for a Maven project.
PREREQUISITES:
• Jenkins Installed: Ensure Jenkins is installed and accessible.
• Source Code Repository: Code should be stored in a version control system like
GitHub, GitLab, or Bitbucket. Here:
https://github.com/MADHAVAN-BE-2003/Maven_Project_Test.git
PROCEDURE:
1. Set Up Jenkins
a. Log in to Jenkins: Open your Jenkins instance in a web browser
http://localhost:8080/
https://github.com/MADHAVAN-BE-2003/Maven_Project_Test.git
C:\ProgramData\Jenkins\.jenkins\workspace\My-CI-Pipeline>mvn test
[INFO] Scanning for projects...
[INFO] --------------------< com.example.crudapp:crud-app >--------------------
[INFO] Building crud-app 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] --- resources:3.0.2:resources (default-resources) @ crud-app ---
[INFO] --- compiler:3.8.1:compile (default-compile) @ crud-app ---
[INFO] --- resources:3.0.2:testResources (default-testResources) @ crud-app ---
[INFO] --- compiler:3.8.1:testCompile (default-testCompile) @ crud-app ---
[INFO] --- surefire:2.22.1:test (default-test) @ crud-app ---
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.crudapp.AppTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.059 s - in
com.example.crudapp.AppTest
[INFO] Results:
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.153 s
[INFO] Finished at: 2024-11-12T03:03:14+05:30
[INFO] ------------------------------------------------------------------------
[Pipeline] echo
Tests executed successfully.
[Pipeline] echo
Cleaning up workspace post-build.
[Pipeline] node
Running on Jenkins in C:\ProgramData\Jenkins\.jenkins\workspace\My-CI-Pipeline@2
Build and test stages completed successfully.
[Pipeline] End of Pipeline
Finished: SUCCESS
RESULT:
Thus, the CI pipeline was successfully established in Jenkins, automating the Maven
build process and enabling efficient management of code integration and deployment within
the software development lifecycle.
EXP NO: DATE: ___/___/_____
AIM:
To create a Continuous Deployment (CD) pipeline in Jenkins that automates building,
testing, and deploying code to a cloud environment.
PROCEDURE:
1. Set Up Jenkins
a. Ensure Jenkins is running with required plugins for cloud deployment. Add
ii. Follow your operating system's installation steps, then start Jenkins.
i. Ensure the Jenkinsfile for your Maven project is configured with the
3. Configure Deployment
a. AWS Deployment (S3 Example)
i. Install AWS CLI:
1. Install and configure AWS CLI on your Jenkins server or local
machine.
aws configure
az login
https://github.com/MADHAVAN-BE-2003/Maven_Project_Deploy.git
[Pipeline] checkout
[Pipeline] timeout
Timeout set to expire in 1 hr 0 min
[Pipeline] echo
Workspace cleaned successfully.
[Pipeline] checkout
[Pipeline] echo
Code checkout successful.
C:\ProgramData\Jenkins\.jenkins\workspace\Maven-CD-Pipeline>mvn test
[INFO] Scanning for projects...
[INFO] --------------------< com.example.crudapp:crud-app >--------------------
[INFO] Building crud-app 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] --- resources:3.0.2:resources (default-resources) @ crud-app ---
[INFO] --- compiler:3.8.1:compile (default-compile) @ crud-app ---
[INFO] --- resources:3.0.2:testResources (default-testResources) @ crud-app ---
[INFO] --- compiler:3.8.1:testCompile (default-testCompile) @ crud-app ---
[INFO] --- surefire:2.22.1:test (default-test) @ crud-app ---
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.example.crudapp.AppTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.045 s - in
com.example.crudapp.AppTest
[INFO] Results:
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.011 s
[INFO] Finished at: 2024-11-12T03:17:52+05:30
[INFO] ------------------------------------------------------------------------
[Pipeline] echo
Tests executed successfully.
C:\ProgramData\Jenkins\.jenkins\workspace\Maven-CD-Pipeline>if not exist "D:\Deployed" mkdir
"D:\Deployed"
C:\ProgramData\Jenkins\.jenkins\workspace\Maven-CD-Pipeline>copy
"C:\ProgramData\Jenkins\.jenkins\workspace\Maven-CD-Pipeline\target\crud-app-1.0-SNAPSHOT.jar"
"D:\Deployed"
1 file(s) copied.
[Pipeline] echo
Deployment completed successfully.
[Pipeline] echo
Cleaning up workspace post-build.
[Pipeline] node
Running on Jenkins in C:\ProgramData\Jenkins\.jenkins\workspace\Maven-CD-Pipeline@2
[Pipeline] echo
Build, test, and deploy stages completed successfully.
[Pipeline] End of Pipeline
Finished: SUCCESS
RESULT:
Thus, The configured CD pipeline in Jenkins now automatically builds, tests, and
deploys the project to the target environment. Local machine adjustments enable consistent
processes across cloud and local setups, verifying artifact presence in the defined directory or
cloud storage.