Install TFS 2015 Build Agent on Premises


In the previous article, I showed how to install and configure Maven on the TFS Build server to build Java applications. This article however applies to either Java or .NET applications. This article is based on the version 1 of Build Agent TFS 2017 has a new build agent that I will blog about in the future.

Download the Build Agent

  • Go to http://<tfsUrl&gt;:8080/tfs/_admin
  • Click on the Agent pools tab
  • Click on Download agent
  • Extract the contents of the zip file to c:\Agents\1

Configure Build Agent as a Service (without executing UI Testing)

TFS Build Agents can run as a service or a user. From my experience, most build agents run as a service. You need to run as a user or interactively, when you have a build that performs UI testing such as Selenium or CodedUI.

  • Open command line
  • C:\Agents\1\ConfigureAgent.cmd


  • I have used the default options. When you enter the tfs url, make sure you add /tfs at the end of the url
  • The default user account is Network Service. You can use domain user account if you need to control the permissions

Configure Build Agent in Interactive mode (to Run Selenium or other UI Tests)

In this case, we need to configure the build agent to run interactively (i.e. answer to install ‘N’ it as a service). I also created a new Pool and called it Interactive to group all the agents that run in interactive mode.

  • Open command line
  • Extract the agent into C:\Agents\2
  • C:\Agents\2\ConfigureAgent.cmd


  • As mentioned above, I am using the new pool which is called Interactive and the agent is not running as a service.
  • When you enter the tfs url, make sure you add /tfs at the end of the url

View Agents on the Web Portal

  • Go to http://<tfsurl&gt;:8080/tfs/_admin/_AgentPool
  • Agents colour coded in green means that that they are online and connected to TFS. Otherwise, they will show in red
  • From this screen you can also disable or delete an agent



Categories: TFS2015, Uncategorized Tags: , ,

Configure a TFS 2015 Build Server for Java


Introduction

TFS 2015 comes with a new build engine. It supports building many programming languages such as .NET, Java, Xcode, Android and other languages. You can even have a build agent on Linux. For more information visit https://msdn.microsoft.com/en-us/Library/vs/alm/Build/feature-overview

In this document, I will show how to configure a build server to run Java Maven builds.

Installing maven

System Requirements (Copied from Maven website)

  • Java Development Kit (JDK) Maven 3.3 requires JDK 1.7 or above to execute – it still allows you to build against 1.3 and other JDK versions by Using Toolchains
  • Memory No minimum requirement
  • Disk Approximately 10MB is required for the Maven installation itself. In addition to that, additional disk space will be used for your local Maven repository. The size of your local repository will vary depending on usage but expect at least 500MB.
  • Operating System No minimum requirement. Start up scripts are included as shell scripts and Windows batch files.

Installing Java

Make sure you install the JDK and not just the JRE. Other than that, the installation itself should be straightforward

Create the Environment Variable JAVA_HOME

  • Go to Control panel –> System and Security –> System –>Advanced system settings –> Advanced –> Environment Variables
  • Add new System variable and enter JAVA_HOME as “the Variable name” and jdk path


  • Restart the machine
  • To test, open commandline and type echo %JAVA_HOME%

Download Maven

At the time of writing this document, Maven 3.3.9 was the latest version of Maven. Download Binary zip archive from http://maven.apache.org/download.cgi. I created a folder at c:\JavaTools to have my Java related tools. I extracted the contents of the zip file into c:\JavaTools folder


Test Maven from commandline by typing c:\JavaTools\apache-maven-3.3.9\bin\mvn -v . If you have all the prerequisites, you should see something similar to the following output

c:\JavaTools\apache-maven-3.3.9\bin\mvn -v

Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T11:41:47-05:00)

Maven home: c:\JavaTools\apache-maven-3.3.9\bin\..

Java version: 1.8.0_72, vendor: Oracle Corporation

Java home: C:\Program Files\Java\jdk1.8.0_72\jre

Default locale: en_US, platform encoding: Cp1252

OS name: “windows server 2008 r2”, version: “6.1”, arch: “amd64”, family: “dos”

Create an M2_HOME Environment Variable

  • Create M2_HOME system variable with a value of the Maven folder


  • Restart the machine logout and log back in

What’s Next

In the next blog post, I will show how to install and configure Team Build agents in TFs 2015.

Categories: TFS2015, Uncategorized Tags: ,

Use PowerShell to call TFS 2015 REST API’s


Few months ago, I was helping a client upgrading from TFS 2010 to 2015. After the upgrade, we were getting a message that says “This feature cannot be used until you configure it for this team project”.

Long story short, I had to upgrade the process template for over 77 team projects. Luckily they were all created using the Agile template🙂 The process involves running some commands for the collection and others for each team project. That’s when I decided to script it with PowerShell.

In this post, I will show how to use Powershell to call the TFS 2015 REST API. Let me know in the comment section if you are interested in the script to upgrade the process template.

Show me the code

I am using the “Get list of team project” API which is listed at https://www.visualstudio.com/en-us/docs/integrate/api/tfs/projects


$tfsUrl = 'http://tfsUrl:8080/tfs/'
$collectionName = 'DefaultCollection'
$collectionUrl =  "$($tfsUrl)$($collectionName)"
# Construct the Get list of team projects url
$getProjectsUrl = "$($collectionUrl)/_apis/projects/?api-version=1.0"

# Call the REST API using Invoke-RestMethod. -UseDefaultCredentials for using windows authentication
$json = Invoke-RestMethod -UseDefaultCredentials -uri $getProjectsUrl
$formatedJson =  $json | Format-List
Write-Output $formatedJson

The value field contains the data we need. It is just a matter of extracting the project names from the value field

$tpNames = $json.value | select name
Write-Output $tpNames

The above snippet only shows you a list of project names on the screen. Lets do something more interesting. Let’s say we want create a new team for each team project in a collection and call it Database Team

# Create team API
$createTeamUrl = "$($collectionUrl)/_apis/projects/{0}/teams?api-version=2.2"
#Json that contains the data to be POSTed
$Body = @{
            name = "Database"
            description = "Database Team"
        }

# for each team project, create a team called Database by doing a post request to the create team api
$json.value.ForEach({
    Invoke-RestMethod -Method Post -UseDefaultCredentials -uri ($createTeamUrl -f $_.name) -Body (ConvertTo-Json $Body) -ContentType "application/json"
})

Conclusion

It is really convent and powerful to use Powershell or any other scripting language to TFS’s REST API. To learn more about TFS’s REST APIs visit https://www.visualstudio.com/en-us/docs/integrate/api/overview

Fix TFS 2015 Build’s Queue is Empty


Today I wasn’t able to select a queue while creating a build definition or queuing a build using the new build engine that comes with TFS 2015. The drop down was blank.

This problem may occur if you don’t have build queues for your Collection or if you don’t have permission to use the queues in your build definition.

Go to the administration site for your collection

Check if you have queues for Collection

If you do, select your queueĂ  Role Ă  Agent Queue Users Ă  Double click on Agent Queue Users Ă  add users or groups

Otherwise click the “New queue” link to create a new queue

TFS Build 2015 Gated Check-in Announced


In case you missed the news, the Visual Studio product team at Microsoft has announced the Gated check-in support for TFS Build 2015 (aka Build vNext) for TFVC repository. For more info visit

https://msdn.microsoft.com/en-us/Library/vs/alm/Build/news/2016

 

 

 

Categories: TFS2015, Uncategorized Tags: , ,

Maven test runs fail on some machines


Today I got this error when I ran a Maven build with the test goal on the new build server that I configured to compile the Java code.

[INFO] — maven-compiler-plugin:3.1:compile (default-compile) @ xxxxxx —
[INFO] Changes detected – recompiling the module!
[INFO] Compiling 67 source files to C:\Sc\ xxxxxx \target\classes
[INFO] ————————————————————————
[INFO] BUILD FAILURE
[INFO] ————————————————————————
[INFO] Total time: 6.551 s
[INFO] Finished at: 2016-02-08T17:31:25-05:00
[INFO] Final Memory: 11M/61M
[INFO] ————————————————————————
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project xxxxxx Compilation failure -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

I have the same .m2 folder as the other build severs. Maven and the JDK are configured properly as well. The only difference turned out to be that this server had a newer version of the Java JDK than the other servers. After inspecting the pom.xml file, I noticed that the maven-compiler-plugin had the javac.exe path hard coded

<plugin>

<artifactId>maven-compiler-plugin</artifactId>

<version>3.1</version>

<configuration>

<fork>true</fork>

<executable>C:\Program Files\Java\jdk1.8.0_66\bin\javac.exe</executable>

</configuration>

</plugin>

I removed the hardcoded path and specified the Java version instead.

<plugin>

<artifactId>maven-compiler-plugin</artifactId>

<version>3.1</version>

<configuration>

<fork>true</fork>

<source>1.8</source>

<target>1.8</target>

</configuration>

</plugin>

You can also follow the instructions at http://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html to target multiple versions of the JDK

Categories: Java Tags: , ,

Azure Cloud Load Testing – Part 2


In the previous blog post, I showed how easy it is to initiate a load test from Azure by just providing a URL of the web page you want to load test, specify the number of users and the duration. This is great for websites where requests are GET requests or you are not trying to test a user scenario that consists of multiple steps. In this post, I will show how to use Azure Cloud Load Testing in a more advanced scenario that consists of multiple steps.

Prerequisites

In order to record a performance test which will be used for load testing, you need to have Visual Studio Enterprise or Ultimate Edition. You can download a 30 day trial version

Recording a Scenario

  • Open Visual Studio
  • Create a new Web Performance and Load Test project

  • Click the record button on your web test

  • Go through the scenario you want to record. I uploaded the scenario I recorded at https://youtu.be/6-ZiIL7yPpA
  • I recorded a test to go from the home page to the search page and then perform a search

You can test your script by clicking the run test button

Create a Load Test

A load test can consist of one or more test scenario. You can also define the duration of your test and the number of users to simulate running the test. Let’s create and configure a load test which will run in Azure.

  • Right click on your project
  • Add a load test by right clicking on the project and add a new itm

  • On the wizard, I am selecting a Cloud-based Load Test and click next

  • Select the location where the load will be generated from and click next

  • On the Run Settings page, you select the duration of the run and then click next

  • On the scenario page, name the scenario and select the Think time profile, think time is the duration between your test steps

  • On the Load pattern page, you can select a constant load of users or if you want to start with a smaller number of users and ramp up the user users while your test is running. I am using a constant load but you may want to use the second option if that what you want to simulate.

  • On the test mix page, you can select one or more tests. in my case I am only selecting one web test. You can also selected MSTest unit tests as well.

  • Add the browsers you want your users to use during the test

  • Click the Run load test button

  • Click on the Performance or Throughput buttons to see the graphs. The application button with capture the Application Insights telemetry

Conclusion

In this post, I showed how to create a performance and load test using Visual Studio 2015 Enterprise Edition and leverage Azure Cloud Load Testing to execute the recorded test. I didn’t have to create any Virtual Machines or install test agents to run my load test. I had to push a button and monitor the test run. Cloud load testing would save you a lot of money in infrastructure purchases and labour costs when you want to run load tests to similar millions of users and you want to only run the test scenarios for few weeks a year. The first 20,000 Virtual User Minutes (VUMs) a month are free. Give it a try today.