How To Do A Mvn Clean From Azure Devops
Build your Jump Kick project using Azure Pipelines in Azure DevOps
Today nosotros will have a deep swoop into building your Spring Boot Maven project in Azure DevOps. Stride by step, nosotros will:
- Create a simple Spring Boot Maven project and push button it to Azure Repos
- Build an Azure pipeline to execute a Maven build
- Build a Docker image for our Spring Boot application using the Spring Boot Maven plugin leveraging Cloud Native Buildpacks
- Create a Docker Container registry in Azure
- Push the Docker image to Azure Container Registry
- Pull the Docker paradigm and run it on your local machine
What Azure DevOps?
Azure DevOps is a deject service powered past Microsoft that enables teams to collaborate on software development through source control (Azure Repos), work tracking (Azure Boards), and continuous integration and delivery (Azure Pipelines).
Prerequisites:
- You take admission to Azure DevOps using a Microsoft or Github account. If you don't have one create a free account (5 free users, 1.800 free Azure Pipelines minutes + 2GB of free Azure Artifacts storage).
- Yous take a Microsoft Azure business relationship (but required to publish Docker containers to the Azure Container Registry). If yous don't take 1, you tin can create i and start for complimentary.
- Yous have both the Azure CLI and Docker installed.
Create an Azure DevOps project
To get started we commencement need to create a projection within Azure DevOps:
Create a new project: spring-boot-example. Y'all can eighter arrive public (so everyone on the internet can see the project) or brand information technology private (merely people you give access can run into the project).
Nice your projection has been created!
Create A Spring Boot application
Go to beginning.spring.io to create a new Leap Boot project:
Spring Kick version: 2.3.x
Since we volition use Cloud-Native Build Packs to create a Docker epitome for the Leap Boot application using the Leap Kick Maven plugin, we need at least version ii.iii of Spring Boot!
Java: 11
Starter dependencies: Spring Spider web + Spring Boot Actuator
Project: Maven
Press the push Generate to download a zip file that contains the initial Spring Kick Maven projection.
Clone the Azure Repo
By creating the project in Azure DevOps, a Git repository was automatically created. The next stride is to clone the Git repo and to push button the Leap Boot projection.
Let'due south starting time clone the Azure Git repo:
git clone git@ssh.dev.azure.com:v3/yournamehere/spring-boot-case/spring-boot-example
I'grand using ssh key authentication to connect to the Git repository in this example.
SSH public central hallmark works with an disproportionate pair of generated encryption keys. The public key is shared with Azure DevOps and used to verify the initial ssh connexion. The private cardinal is kept safe and secure on your system.
Brand sure to create a public and individual key pair and set up your ssh central correctly in Azure DevOps in case yous run into this error while cloning the Git repository:
git clone git@ssh.dev.azure.com:v3/yourname/spring-boot-example/spring-boot-example Cloning into 'spring-boot-case'... remote: Public key hallmark failed. fatal: Could not read from remote repository. Please make sure you lot have the correct admission rights and the repository exists.
Go to User settings and select SSH public keys:
Paste your public SSH key, which is normally contained in the file ~/.ssh/id_rsa.pub And begins with ssh-rsa. Never paste your private SSH key, every bit that can compromise your identity!
Push the Bound Boot project to the Azure repo
Make certain y'all are in the cloned git repo directorybound-kicking-example :
cd spring-kicking-instance Excerpt the zip file of the Leap Boot projection into a temporary directory
unzip ~/Downloads/jump-boot-example.zero -d /tmp
movement the files, directories including hidden files (like .gitigore and .mvn wrapper directory) into the cloned repository directory
mv /tmp/spring-boot-example/* .
mv /tmp/jump-boot-example/.* . Add a uncomplicated Residue Controller to the projection.
and a uncomplicated Bound MVC test for the SimpleController:
Add the source code to git, commit, and button the code:
git add .
git commit -m "Initial Spring Boot project"
git push Nice the code is committed and visible in Azure DevOps!
Create your first Azure pipeline
Now the source code is committed to the Azure Git repo of your project. We tin commencement building the Spring Boot project using Azure Pipelines.
In this office of the blog post, we will configure an Azure pipeline to build the Spring Boot application with Maven.
First, go to Pipelines and click the button Create Pipeline:
Select: 'Azure Repos Git'
Select the repository: spring-boot-example
Nosotros choose Maven to configure the pipeline:
Pipelines in Azure DevOps follows the principle of pipelines as code. This technique emphasizes the configuration of (commitment) pipelines that:
- builds the software
- runs automated test
- and deploy the application
should be treated as code and are placed nether source control.
Azure DevOps will come up with an initial pipeline definition to build the Spring Kick project using Maven. The steps and tasks in the pipeline are defined in a azure-pipelines.yml configuration file.
You lot can customize the pipeline configuration on this screen and see the available input parameters:
The initial Maven build step for the pipeline:
Changed the JDK version to Coffee 11.
Let'southward get over the pipeline definition:
Triggers:
-
trigger: A list of triggers to offset a new pipeline job. In this case, every commit tomastervolition exist the trigger to build the projection.
Hosted Agents pool:
-
pool: Pipeline jobs are executed in a pool of Microsoft-hosted agents. The maintenance and upgrades of those hosted agents are taken care of for you. Each time you run a pipeline, you get a fresh virtual car. The virtual machine is discarded subsequently one use. You lot can specify the proper noun of the VM image you desire to usingvmImagein this example, the build will be executed on the latest ubuntu version (ubuntu-latest).
For a complete listing of VM images, meet the Microsoft hosted agents documentation.
The Ubuntu VM image used in the pipeline is managed past Microsoft and comes with pre-installed development tools we use in the pipeline:
- Java (AdoptOpenJDK 1.8, xi and 12)
- Maven 3.six.3
- Git 2.28.0
- Docker
You tin find the operating system, and virtual environment (including a link to the list of pre-installed tools) used during the build in the Initialization step of the pipeline job.
For a complete listing of pre-installed runtimes, CLIs and tools check the Ubuntu GitHub Actions Virtual Environments documentation.
Maven step:
-
mavenPomFile: A Project Object Model (POM) is the central unit of measurement of work in Maven. It is an XML file that contains information about the projection and configuration details used by Maven to build the project. Using this holding, you lot can specify the relative path from the repository root to the Maven POM file. For this Leap Boot example application, the pom file is at the root of the project.
Default value:pom.xml -
mavenOptions: Sets the MAVEN_OPTS surroundings variable, which is used to send control-line arguments to starting time the JVM. The -Xmx flag specifies the maximum memory available to the JVM.
Default value:-Xmx1024m -
javaHomeOption: Sets JAVA_HOME either by selecting a JDK version that will be discovered during builds or by manually inbound a JDK path.
Default value:JDKVersion -
jdkVersionOption: The specified JDK version to build the projection. For our project, we useone.11(Java xi) instead of1.8.
Default value:default -
jdkArchitectureOption: The architecture (x86, x64) of the JDK
Default value:x64 -
publishJUnitResults: Whether or not to publish the Junit test results produced by the Maven build to Azure Pipelines.
Default value:true -
testResultsFiles: The Maven (unit of measurement) exam reports are generated by the Maven Surefire plugin and are available after a Maven build in the directory:target/surefire-reports. Using this belongings, you tin can specify the path and pattern of exam results files to publish to Azure DevOps.
Wildcards can be used.
This belongings is required whenpublishJUnitResultsis set totrue.
Default value:**/surefire-reports/Test-*xml -
goals: The Maven goal to run. In our case, run thepackagegoal to compile your code, run tests, and package the project into an executable jar file.
Default value:package
Y'all can find a complete list of all the Azure Pipeline Maven configuration options in the Azure Pipelines Documentation.
Now salvage and run the pipeline:
Yous now have an Azure pipeline definition (azure-pipelines.yml) in your repository that's gear up to build the Leap Boot project. In the next parts of this blog post, we are going to customize the pipeline.
First build pipeline is running:
Passed:
View the details of the build chore:
check out the examination results (by clicking the 100% tests passed link):
Hooray, all the tests passed!
Build a Docker epitome using Cloud Native Buildpacks
Buildpacks provide a college-level brainchild for edifice applications compared to Dockerfiles. The job of a buildpack is to find and get together everything your application needs to build and run.
Long story curt, a buildpack volition transform your source code into a runnable OCI application image! For more information, check out: https://buildpacks.io
Spring Boot 2.3 introduced the support for building Docker images using Cloud Native Buildpacks has been added to the Spring Kick Maven plugin.
Let'south add together a second Maven pace in the pipeline to build the Docker image:
To build the image for your Leap Kicking application, nosotros use the leap-kicking:build-image goal of the Spring Boot Maven plugin. For this build, we don't publish Junit test results back to Azure DevOps.
Optionally you can add a displayName for the build step. This convenient name is displayed in the UI of the pipeline chore.
Commit the pipeline changes:
A new build will start including the 'Build Docker image' step:
Swell the Docker image was build successfully! Since the Ubuntu VM, the build job is running on already contains Java eleven, Maven and Docker edifice the image works out of the box. If you are only interested in building an image for your project you can get out out the starting time Maven build pace (maven packet) from the pipeline.
In the adjacent step of this blogpost, we will push the Docker image to a private Container Registry in Azure.
Create an Azure Container Registry
Azure provides a fully managed Docker registry called Azure Container Registry. Azure Container Registry allows you to build, store, and manage container images and artifacts in a private registry for all types of container deployments.
Be aware the Azure Container Registry is not a complimentary service!
See: Azure Container Registry Pricing
Log in to the Azure portal.
And search for service: 'Container Registry'
You don't accept whatsoever container registries yet:
Create a new resource group and container registry:
Give the container registry a name:
Review and create the container registry:
The container registry is ready.
Re-create the name of the container registry.
Button the Docker image
By default, the name of the image is based on the artifactId and the version of your Maven projection and fix to be published to DockerHub:
docker.io/library/${project.artifactId}:{project.version} Add together configuration for the prototype in the build section of the pom.xml file of the Jump Boot projection:
The image proper name configuration must friction match your Azure Container Registry server proper noun! This configuration also enables building layered jars. Layered jars are beyond the scope for this blog mail, but you tin larn more about it in my previous blog post: What'south new in Jump Kick ii.3.
Let's add a step to the pipeline to button the Docker image to the Azure Container Registry.
There is no container registry to button the Docker epitome to:
Navigate to project settings and click on menu item 'Service Connection'
Create a service connection. You need to authenticate to create the service connexion between Azure pipelines and the external Azure Container registry.
Select Azure Container Registry as the 'Registry blazon', select your subscription and container registry. Now give the service connectedness a name.
The service connexion between Azure DevOps and the private Azure Container Registry is ready:
and the service connection tin now be used in the next Docker pace to push the epitome:
Docker task to push the image of the application to the individual Azure Container registry:
The consummate pipeline definition:
This Docker task volition:
-
tagthe image as the latest - execute a docker
pushtorepositorywith namebound-boot-exampleof the container registry, nosotros configured using the service connection.
This pace volition show in the Azure Pipelines UI withdisplayName 'Push Docker image'
Commit the changes:
And check the image will exist pushed to the Azure Container Registry:
Head over to Azure and see the epitome is bachelor in the Container Registry:
Pull and run the Docker epitome
Now the Docker prototype is available in the Azure Container Registry let's try to run the application using Docker. First login to your Azure account using the Azure CLI (a browser volition open up):
az login Login to the Azure Container registry:
az acr login --proper noun yourcontainerregistry Pull the Docker paradigm:
docker pull yourcontainerregistry.azurecr.io/spring-kick-case:latest Now run the Docker image on your machine:
docker run -p 8080:8080 -d --name spring-boot-example yourcontainerregistry.azurecr.io/spring-kicking-case:latest Open the browser:
To stop the Docker container:
docker stop spring-boot-example Wrapup
Azure DevOps is a squeamish tool that provides development teams with an end-to-terminate DevOps toolchain. The pre-installed development tools on the build VMs provided past Microsoft makes information technology super easy getting started with Azure Pipelines to build your Spring Boot Maven project, including Docker images using Deject Native Buildpacks.
Interesting links
- Azure DevOps: https://dev.azure.com
- Azure Portal: https://portal.azure.com
- Azure Pipelines YML schema reference
- Azure Pipelines Maven Documentation
- Spring Kick: https://spring.io/projects/spring-kick
- Deject-Native Buildpacks: https://buildpacks.io
Tap the 👏 button if you found this article useful!
Any questions or feedback?
Reach out to me on Twitter: @TimvanBaarsen
Source: https://medium.com/@TimvanBaarsen/build-your-spring-boot-project-using-azure-pipelines-in-azure-devops-3305977991d
Posted by: wilkinablempoore.blogspot.com

0 Response to "How To Do A Mvn Clean From Azure Devops"
Post a Comment