Continuous integration(CI) and continuous delivery(CD) pipelines have become the norm in software engineering. In the corporate world, a CI/CD pipeline is especially useful to ensure your entire development team is following the best quality guidelines and drastically shorten the deployment cycle to satisfy your customers. Thus why all Cloud providers are now providing their CI/CD pipeline platform. In this tutorial, we will focus on how to use the Azure DevOps platform on a Java project.
Create a new Java spring web application on Azure App Service:
- Log on portal.azure.com
- Navigate to the App Services
- Add a new Web App
- Select your existing subscription level
- Remember its name
Create a new Java DevOps project on Azure DevOps:
- Log on dev.azure.com with the same Azure account
- Create a “new project” and enter the needed information
![](https://cedricleruth.com/wp-content/uploads/2020/02/Selection_001.png)
![](https://cedricleruth.com/wp-content/uploads/2020/02/Selection_001.png)
- Navigate to the project settings and activate all the services
![Azure Devops services selection screenshot](https://cedricleruth.com/wp-content/uploads/2020/02/Selection_014-1024x593.png)
![Azure Devops services selection screenshot](https://cedricleruth.com/wp-content/uploads/2020/02/Selection_014-1024x593.png)
- Navigate to the “Repos” Service and import your Java code or Clone an existing git. (For this example take any sample spring web app on GitHub: https://github.com/ragsns/hello-world-spring-boot.git)
![Azure Devops pipeline clone repository screenshot](https://cedricleruth.com/wp-content/uploads/2020/02/Selection_003-1024x400.png)
![Azure Devops pipeline clone repository screenshot](https://cedricleruth.com/wp-content/uploads/2020/02/Selection_003-1024x400.png)
- Your Repository code is available as below
![Azure Devops repos files screenshots](https://cedricleruth.com/wp-content/uploads/2020/02/Selection_004-1024x211.png)
![Azure Devops repos files screenshots](https://cedricleruth.com/wp-content/uploads/2020/02/Selection_004-1024x211.png)
Create a build pipeline with Maven on your Azure DevOps Repository:
The objective here is to build your Java application everytime there is a commit or a merge on your master branch.
- Navigate to your Repository > Files > Set up build > New Pipeline > Configure > Maven Package
![Azure Devops configure your pipeline screenshot](https://cedricleruth.com/wp-content/uploads/2020/02/Selection_005.png)
![Azure Devops configure your pipeline screenshot](https://cedricleruth.com/wp-content/uploads/2020/02/Selection_005.png)
- Azure DevOps will generate its own azure-pipelines.yml as follow:
- To test your build pipeline, simply modify a file in your repository master branch.
![Azure Devops build Maven pipeline screenshot](https://cedricleruth.com/wp-content/uploads/2020/02/Selection_007-266x300.png)
![Azure Devops build Maven pipeline screenshot](https://cedricleruth.com/wp-content/uploads/2020/02/Selection_007-266x300.png)
Create a publish pipeline on your Azure DevOps Pipeline tool:
Now that we have a build pipeline to continuously test and build our codebase we can create a release pipeline to continuously deploy our modification to a development server.
- Navigate to Repository > Releases > New Release Pipeline
- Select a Template > Empty Job
- Add a new stage to your empty build pipeline
![Azure Devops release pipeline add stage screenshot](https://cedricleruth.com/wp-content/uploads/2020/02/Selection_008-1024x413.png)
![Azure Devops release pipeline add stage screenshot](https://cedricleruth.com/wp-content/uploads/2020/02/Selection_008-1024x413.png)
- On this new release, pipeline navigate to Artifact > Add > Source > java_pipeline_demo_build (or any other name you gave it)
![Azure Devops add an artifact to your pipeline screenshot](https://cedricleruth.com/wp-content/uploads/2020/02/Selection_009-1024x461.png)
![Azure Devops add an artifact to your pipeline screenshot](https://cedricleruth.com/wp-content/uploads/2020/02/Selection_009-1024x461.png)
Now we need to specify on wich Azure App Service to deploy our Java artifact:
- On this new release, pipeline navigate to Tasks > Dev > Agent Job > + > Azure App Service Deploy
- Connection Type: Azure Ressource Manager
- Azure Subscription: YOUR_SUBSCRIPTION
- App Service type: Web app on Linux
- App Service Name: THE_NAME_YOUR_PROVIDED_ON_STEP_1
- Package or folder: Select the .war
- Runtime stack: Java SE (JAVA|8-jre8)
![Azure DevOps release pipeline deploy screenshot](https://cedricleruth.com/wp-content/uploads/2020/02/Selection_010-1024x451.png)
![Azure DevOps release pipeline deploy screenshot](https://cedricleruth.com/wp-content/uploads/2020/02/Selection_010-1024x451.png)
- On this new release, pipeline navigate to Pipeline > Artifact > Continuous deployment trigger > Enable
- Name the pipeline
- Save
- Create Release
![Azure DevOps release pipeline test and deploy screenshot](https://cedricleruth.com/wp-content/uploads/2020/02/Selection_013.png)
![Azure DevOps release pipeline test and deploy screenshot](https://cedricleruth.com/wp-content/uploads/2020/02/Selection_013.png)
That’s it. From now on each commit on your Azure DevOps repository will trigger a build pipeline. The Java Artifact built will trigger a release pipeline. This release pipeline will add this Java Artifact to your Azure App Service server seamlessly deploying your modifications.