Ex.
No:1
Create Maven Build pipeline in Azure
Date:
Aim
To create a maven project and build a pipeline in Azure.
Procedure
1. Install Java and Maven and set the system environment variables
a. Download maven and extract it
b. Add JAVA_HOME and MAVEN_HOME in environment variable
1. Right click on MyComputer -> properties -> Advanced System
Settings -> Environment variables -> click new button.
2. Add MAVEN_HOME in variable name and path of maven in variable
value. click on OK button. Similary create JAVA_HOME
c. Add maven and java path in environment variable
. Click on new tab and then set the path of maven and java till
bin directory. If it is set, edit the path and append the path of maven
and java
d. Verify Maven and Java
open the command prompt and write:
1. mvn −version
2. java -version
2. Create a github account
1. Go to https://github.com/join in a web browser
2. Enter your personal details.
3. Click Verify to start the verification puzzle.
4. Click the green Create account button.
5. Verify your email by entering the code.
6. Select your preferences and click Continue.
7. Note the types of plans offered by GitHub.
8. Select the free plan.
3. Create an Azure student login and enter into Azure DevOps Create an Azure
Student Account:
• Visit the Azure for Students page.
• Sign up using your university or school email. You’ll need to renew this
account each year while you’re a student.
• You’ll receive a USD 100 credit to use with Azure services. No credit card is
required, and you get 12 months of free Azure services1.
Sign Up for Azure DevOps:
• Go to Azure DevOps.
• Choose either a Microsoft account or a GitHub account to sign up. If
you don’t have a Microsoft account, create one.
• Select Start free and enter your account credentials.
• Azure DevOps will create an organization for you.
• It will also create a project named after your newly created Microsoft
account. If you signed up with an existing Microsoft account, you’ll
need to create a project next.
Access Azure DevOps:
• Sign in to your organization anytime at dev.azure.com{Your_Organization}.
4. Install a Java IDE (Eclipse, NetBeans, IntelliJ IDEA, VS code)
5. Develop a Java Maven Project and build the application in the local server
Create a New Maven Project:
• Open VS Code.
• Install the Maven for Java extension by searching for it in the Extensions
view (Ctrl+Shift+X).
• Create a new Maven project using one of the following methods:
Use the command palette (Ctrl+Shift+P) and type “Maven: Create
Maven Project.”
• Right-click on a folder and select “Generate from Maven Archetype.”
• Choose the “maven-archetype-quickstart” archetype.
• Modify the pom.xml file to specify your project details and dependencies.
Write Your Java Code:
• Create your Java classes in the src/main/java directory.
• Define your application logic, classes, and methods.
Build the Project:
• Open the integrated terminal in VS Code (Ctrl+`).
• Run the following command to build the project:
mvn clean install
• This will compile your code, run tests, and package the application into a
JAR file.
Run the Application Locally:
• After successful build, use the following command to start a local server:
java -jar target/your-artifact-id-version.jar
• Replace your-artifact-id-version with the actual name of your JAR file.
Access Your Application:
• Open a web browser and navigate to http://localhost:8080 (or the port
specified in your application).
• You should see your Java application running locally.
Procedure
1. Install Java and Maven and set the system environment variables
a. Download maven and extract it
b. Add JAVA_HOME and MAVEN_HOME in environment variable
i. Right click on MyComputer -> properties -> Advanced System Settings > Environment
variables -> click new button.
i. Add MAVEN_HOME in variable name and path of maven in variable value. click
on OK button. Similary create JAVA_HOME
c. Add maven and java path in environment variable
. Click on new tab and then set the path of maven and java till bin
directory. If it is set, edit the path and append the path of maven and java
d. Verify Maven and Java
open the command prompt and write:
i. mvn −version
i. java -version
2. Create a github account
1. Go to https://github.com/join in a web browser
2. Enter your personal details.
3. Click Verify to start the verification puzzle.
4. Click the green Create account button.
5. Verify your email by entering the code.
6. Select your preferences and click Continue.
7. Note the types of plans offered by GitHub.
8. Select the free plan.
3. Create an Azure student login and enter into Azure DevOps Create an Azure
Student Account:
• Visit the Azure for Students page.
• Sign up using your university or school email. You’ll need to renew this
account each year while you’re a student.
• You’ll receive a USD 100 credit to use with Azure services. No credit card
is required, and you get 12 months of free Azure services1.
Sign Up for Azure DevOps:
• Go to Azure DevOps.
• Choose either a Microsoft account or a GitHub account to sign up. If
you don’t have a Microsoft account, create one.
• Select Start free and enter your account credentials.
• Azure DevOps will create an organization for you.
• It will also create a project named after your newly created Microsoft
account.
• If you signed up with an existing Microsoft account, you’ll need to create a
project next.
Access Azure DevOps:
• Sign in to your organization anytime at dev.azure.com{Your_Organization}.
4. Install a Java IDE (Eclipse, NetBeans, IntelliJ IDEA, VS code)
5. Develop a Java Maven Project and build the application in the local server
Create a New Maven Project:
• Open VS Code.
• Install the Maven for Java extension by searching for it in the Extensions
view (Ctrl+Shift+X).
• Create a new Maven project using one of the following methods:
Use the command palette (Ctrl+Shift+P) and type “Maven: Create
Maven Project.”
• Right-click on a folder and select “Generate from Maven Archetype.”
Choose the “maven-archetype-quickstart” archetype.
• Modify the pom.xml file to specify your project details and dependencies.
Write Your Java Code:
• Create your Java classes in the src/main/java directory.
• Define your application logic, classes, and methods.
Build the Project:
• Open the integrated terminal in VS Code (Ctrl+`).
• Run the following command to build the project:
mvn clean install
• This will compile your code, run tests, and package the application into a
JAR file.
Run the Application Locally:
• After successful build, use the following command to start a local server:
java -jar target/your-artifact-id-version.jar
• Replace your-artifact-id-version with the actual name of your JAR file.
Access Your Application:
• Open a web browser and navigate to http://localhost:8080 (or the port
specified in your application).
• You should see your Java application running locally.
6. Push the java maven project into Git Repository Initialize Git Repository:
• Open a terminal or command prompt.
• Navigate to the root directory of your Maven project using the cd command.
Initialize a new Git repository: git init
Add and Commit Your Files:
• Use the following commands to stage all files and commit them: git add .
git commit -m "Initial commit"
Create a New Repository on GitHub:
• Go to GitHub and log in (or sign up if you don’t have an account).
• Click the “+” icon in the top right corner and select “New repository.”
• Give your repository a name, choose visibility (public or private), and create
it.
• Link Your Local Repository to GitHub:
• Copy the HTTPS URL of your newly created GitHub repository.
• In your terminal, add the remote origin (replace <me> with your GitHub
username and <myrepo> with your repository name):
• git remote add origin https://github.com/<me>/<myrepo>.git Push your
code to the master branch on GitHub:
• git push -u origin master
7. Create Azure DevOps organization and import or clone the git repo of the java
maven project
Sign in to Azure DevOps:
• Log in to your Azure DevOps organization.
• Select Your Project:
• Choose the project where your Java Maven project resides.
• CCreate a New Git Repo in Your Project:
• Open the Repos page in your project by browsing to
dev.azure.com/OrganizationName.
• Hover over the name of your project and select the Repos icon.
• From the repo drop-down, select New repository.
• Verify that Git is the repository type and enter a name for your new
repository.
• Optionally, add a README and create a .gitignore file. Select Create.
8. Create a pipeline in Azure and build the project Create a New Pipeline:
• Navigate to Pipelines (usually on the left side menu).
• Click on New pipeline.
• Select Azure Repos Git as the source location.
Choose Your Repository:
• Select the Git repository where your Java Maven project is hosted.
Configure the Pipeline: You’ll be guided through a wizard:
• First, choose the Maven, Gradle, or Ant template based on your build
preference.
• Save your configuration.
• Commit an azure-pipelines.yml file to your repo.
• Save and run the pipeline.
Watch Your Pipeline in Action:
• If you want to see your pipeline executing, select the build job.
Customize Your Pipeline:
• When you’re ready to make changes, go to the Pipelines page, select your
pipeline, and edit the azure-pipelines.yml file.
Output
GitHub Account
Maven Project
Project Settings
1. Choose Agent pools.
2. Click on Add pool.
3. Select Pool-type as Self-hosted, give it a name and click on Create.
4. Click on the created agent pool.
To create an Agent:
• Click on organization setting
- Create a new pool in Agent Pools
- Go inside the pool created and create a new agent
- Follow the steps shown in the screen.
• Give the URL till organization name
• For PAT follow the below steps o Click on Personal Access Tokens
- Create a new token.
- Copy the token and paste it.
Now to create a pipeline
• Go to pipelines in Azure Devops.
• Click GitHub or where your code is stored.
• GitHub is used in this Demo.
- Choose your source code.
- Make sure it is a maven project by verifying whether there is pom.xml in that project.
- Since maven project click on Maven to Generate a sample YAML script for basic test
and build.
• Since we want to create an artifact (jar/war) change the YAML script as given
below trigger:
- master pool: mynewpool
Conclusion:
Thus, a maven project was created and build a pipeline in Azure.