In this lab, we will retrieve our sample Java application from GitHub and trigger a Jenkins build from Visual Studio Team Services (VSTS). Jenkins will build our application using Maven and package it, before VSTS retrieves the package and stores it as an artifact.
This lab aims to get you familiar with how Visual Studio Team Services can retrieve code from a GitHub repository and you can integrate with Jenkins to build and package an application.
You must have completed Lab 01 and Lab 02.
In this session, we will create a GitHub service endpoint that enables us to retrieve the code in a GitHub repository. We will also create a Jenkins service endpoint to enable a connection to Jenkins. Our intention is for Jenkins to build and package the application, VSTS simply queues the Jenkins build and retrieves the package when Jenkins is finished packaging it.
-
Go to your VSTS account (replace your-account-name in the following URL): https://{your-account-name}.visualstudio.com/
-
Click "New" to create a new Team project, and specify following information.
Name: OSSDevOpsHOL
Description: Introduction to open source DevOps practices in the cloud. Hands on labs to show how Visual Studio Team Services integrates with GitHub, Jenkins and Docker.
Process template: Agile
Version control: Git (It doesn't really matter what you select here as we will retrieve our code from GitHub) -
Click "Create project"
We will now create a new service connection to GitHub so that VSTS will have access to our GitHub repository later on in this lab.
-
Create a new GitHub connection by clicking on "+ New Service Endpoint" and selecting "GitHub"
-
Click on the "Authorize" button and follow the steps required by GitHub to authorize access to your account.
-
When access is granted, you will see a message that confirms the connection and you can specify a connection name. Click OK.
-
You should now see the service endpoint you just created in the overview:
We will now create a new service connection to Jenkins so that VSTS will have access to the Jenkins server created in the previous lab.
-
Create a new Jenkins connection by clicking on "+ New Service Endpoint" and selecting "Jenkins"
-
Specify a connection name and the Server URL, Username and Password of your Jenkins server (this was set in Lab 2.2.1)
-
Click "Verify connection" to ensure that VSTS is able to connect to the Jenkins server.
-
When the connection is verified, you will see a message that confirms the connection and you can click OK.
-
You should now see the service endpoint you just created in the overview:
In order for VSTS to find the sample Java application that is used in this lab when it connects to your GitHub account, you will need to fork the repository that contains the application.
-
Go to the hol-oss-devops repository on GitHub and make sure you are logged in with your GitHub user account.
We will now create a new Build Definition that contains all the steps to be executed when we trigger a build. We will enable Continous Integration so that a build is triggered every time you push code to the selected branch in your GitHub repository.
-
Create a new build definition by clicking "+ New definition"
-
Select GitHub as the repository source and mark the "Continous Integration" checkbox. Keep all other settings as-is and click "Create".
-
You should now see a default build definition. We will fill out all necessary information in the following steps of the lab.
-
Go to the "Repository" tab and specify the following information.
Repository type: GitHub
Connection: Select the GitHub endpoint you created earlier in this lab
Repository: Select the forked repository of this lab Default branch: master -
Go to the "Build" tab, select the "Queue Jenkins Job" build step and fill out the following:
Jenkins service endpoint: Select the Jenkins endpoint you created earlier in this lab
Job name: MavenBuild -
Select the "Download artifacts produced by" build step and fill out the following:
Jenkins service endpoint: Select the Jenkins endpoint you created earlier in this lab
Job name: MavenBuild -
Click "Save", supply the name "Queue Jenkins Job & Publish" and click OK.
-
Queue a new build by selecting "Queue new build" and click OK without changing any of the default settings.
-
Let the build run and ensure that it is successful.
-
To view the build summary, click the build number and select "Summary"
-
To view the artifacts that were downloaded from Jenkins, click the "Artifacts" tab. When you explore the artifact from the build you will see that it contains a .war file.