Set up a C# 6 / .NET 4.6 Build Agent for Atlassian Bamboo

Setting up a Remote Build Agent for Bamboo to build your C# code is pretty easy, although it may not be totally clear at first. The main thing to account for is that your code will be built directly using MSBuild rather than Visual Studio. So before you even get Bamboo involved, it is a good idea to just install everything needed for a successful build using MSBuild.

In order to do that, we need to download and install the following:

Installing the Build Tools

The latest .NET 4.6 Developer Pack

This includes the .NET Framework, SDK, and Targeting Packs. As with all .NET 4 previous Framework installations, this replaces any existing .NET 4 installations and exists alongside any pre-.NET 4 installations.

Microsoft Build Tools 2015

This includes MSBuild 14, which you will need to build any Visual Studio 2015 projects. It is also backwards compatible with older Visual Studio projects.

Nuget

As you may have gathered, this will let you rebuild your Nuget references. You need to put this somewhere in the System Path. It’s probably a good idea to have just one folder to all executable files (like nuget.exe) that don’t come with an installer, and don’t need other DLLs. You can add that folder to the system path. I keep these in c:\usr\bin.

Git for Windows

… or a client for whichever SCM you are using.

After you’re done installing the above, you should check-out your code and try building it using MSBuild. You may encounter some errors, as Microsoft Build Tools 2015 will not include many of the assemblies that are included with Visual Studio and referenced by the Project Templates. You would need to add Nuget references for any assemblies that are causing build errors.

Installing the Build Agent

Once you have a successful build, you can proceed installing the Bamboo Build Agent (and Java):

  • Java SE Development Kit 8
  • Bamboo Build Agent: https://{your_subdomain}.atlassian.net/builds/admin/agent/addRemoteAgent.action

Java SE Development Kit 8

The Build Agent is a Java JAR application, and it requires Java 8.

Bamboo Build Agent

You can download the Build Agent JAR from the Build Agent configuration screen in your Bamboo Portal. You can get the direct URL for this screen by replacing the {your_subdomain} portion of the Bamboo Build Agent link above with your sub-domain. Or just follow these screen shots:

Settings -> Agents …

bamboo-buildagent-01

Install remote agent …

bamboo-buildagent-02

For a typical build agent, you want to have the JAR run as a Windows Service. For that you can get the JAR with a service wrapper by clicking the big ‘download’ button in the middle of that page. If you don’t want to run the JAR as a Windows Service, you can use the download link at the bottom of that page. We won’t cover that scenario here though.

Once you have downloaded the JAR file, open a command prompt as Administarator, and CD into the folder containing the JAR. Then you need to copy and paste the Java command in the Running a remote agent section into the command prompt, but DO NOT RUN IT AS IS. You need to run it with an Install parameter, which should look like the following

java  -jar atlassian-bamboo-agent-installer-{version}.jar  https://{your_subdomain}.atlassian.net/builds/agentServer/  -t {security_token}  install

This will install the Bamboo Build Agent files in the %USERPROFILE%\bamboo-agent-home\ path. You need to go into %USERPROFILE%\bamboo-agent-home\bin\ and run the InstallBambooAgent-NT.bat as administrator. This will install the Windows Service, which you can confirm by going into services.msc as shown below.
Bamboo Build Agent Windows Service

Once you start the service, it will register itself with your Bamboo Build Server. You will need to go into the Agents Configuration on your Bamboo Portal and Approve access for this agent before you can use it.

Bamboo Agent Allow-Access

If you already have other Build Agents registered, you will need enough free Build Agent licenses to be able to approve access to it. If you do not have enough licenses, you will need to revoke access for another Build Agent, before you can Approve this one.

Once You’ve approved the Build Agent, you can use it in your Build Plans. Bamboo will automatically detect the MSBuild version you installed on the server, and let you pick that version in the Build Task in your plan. To get the code to compile you will need to add a Script Task to run before the Build Task. The script body should be as follows:

nuget restore {your-solution-filename}.sln

After setting that up, your .NET Project should be successfully building on your new Build Agent.

You can find more information about Remote Build Agents for Bamboo such as licensing requirements etc on the Bamboo website

Author: musaul

Software Developer/Consultant ● Coffee Addict ● Gadget Geek

Leave a Reply

Your email address will not be published. Required fields are marked *