ON THIS PAGE we will show you how to build a Visual Studio Team Services Java project from a Git repository (repo) using Maven.
- You have read the Create a Git Repo page and performed the steps on that page to create a Team Services project and Git repository for the DeepSpace sample code.
Build a Web Application
Throughout all of the pages in this walkthrough, we will consistently use some sample code written in Java and AngularJS. The project is called DeepSpace. All of our instructions in the walkthrough pages and screenshots will assume you are using this same sample code, but would also apply if you had your own code (with names changed appropriately).
Following the instructions below, you will build a Java project (create a WAR file) using Maven. We will lead you through the steps to: 1) Create a new build step using Maven; 2) Configure the Maven build options; 3) Set up continuous integration for the project; and 4) Queue your first build of the project.
Create a Maven build definition
From within your Team Services project, click on the
Build menu option at the top left of the Team Services webpage. If this is your first build definition, you will see
an option in the Definitions pane to
Add build step.
If you already have at least one build definition in your project, you can create a new empty definition by clicking on the green
+ sign in the left build pane (appears
above the build definitions list). Once you click, you should see the
Definition Templates window.
In that window, select the
Empty option (at the bottom of the list) and then press OK.
Add build step as described above.
Using one of the above methods, add a new build step by clicking
Add build step under the "Definitions" window.
Add Tasks window will appear. Within this window, select
Maven (Build with Apache Maven), click the
Add button associated with Maven,
and then press
Close (as shown in the image below).
Configure the Maven build
Once you have created the new build definition including the single build step for Maven, you need to configure the Maven options.
Click on the
... button beside the
Maven POM file text box to locate the pom.xml file.
In the "Select Path" pop-up window, select the pom.xml file in the top level of the
DeepSpace repo and press
OK. This should be the only option you need to configure.
Set up Continuous Integration
Before we save this build definition, let's set up continuous (build) integration to trigger off of changes to the master
branch of the Git repository. This option sets up the Team Services project to automatically build the Java project whenever changes are made
to the master branch. Click the
Triggers option under the Definitions window. Then select the box beside
Continuous Integration (CI).
Save in the Definitions window to save this build definition. You will be prompted to enter a name in the
Save window, so
enter a name such as "First Build Definition" and press
Execute the Build
Now that you have created a build definition, let's manually queue our first build of the project. Click on the
Queue build... menu option under
your "First Build Definition". This will display a window titled
Queue Build For First Build Definition giving you an option to pick a build
queue to use (for now, leave this as
Hosted which will use default Azure build systems). Click
OK. A build progress
Console window will
appear and will reflect the output of the Maven build task. The build can take a few seconds to a minute to begin and may last a few
minutes. You will know the build is complete when a green bar is displayed reading "Build Succeeded" as shown in the image below.
Check Automated Test Results
To check the results of the automated tests, click on your build in the left window pane (Build 1 if this is your first build). This should open a screen that looks similar to the one below (yours may be Build 1, Build 2, etc., depending on how many builds you have performed).
To see the summary results of automated tests, click on the link under the
Test results section in the right window pane.
This will display the Test Run summary for the build in a screen similar to the image below.
Congratulations! You have created and executed your first Maven build successfully. The WAR file generated from this build is on the Azure build server that executed your build. To learn how to deploy this WAR file to a free web server in Azure, continue this walkthrough by following the next steps to deploy the web application.
So now you know how to build a Java project from a Git repo on Team Services using Azure build hosts.
- Deploy a Web App - Learn how to deploy your Java project to Microsoft Azure
Frequently Asked Questions (FAQ)
Q: Where can I learn more about the Team Services build system and options?
A: This Team Services build article provides more details.
Q: How can I create and run a Maven build on Team Services?
A: Watch a how-to video on Maven builds on our YouTube channel.