| 7 min read
> This article is part of blog series VSTS, Xamarin and Continuous Integration. Why does it matter?
When we set up build definitions in Visual Studio Team Services, we require a machine or a host (called Build agent) which will perform all the steps we define in build definitions. For Xamarin iOS projects it is recommended or rather required to have a machine that is running Mac OS or macOS as per new nomenclature.
Why? In order to build iOS apps, Xamarin requires Mac Agent to access iOS SDK, XCode compiler, interface builder, keychain certificates and provisioning profile configurations since Apple has not made those available for other platforms (Sad but we got to accept it).
There are two ways of getting your own build agent. First is to use third party provider like MacInCloud.com which cost you several dollars a month, other alternative is to setup your own build agent. Benefit of having your own build agent is you have total control over it and you can reuse it for other purposes while keeping build agent as a service in background.
This article will walk you through steps required for setting up your own build agent. While there are other tutorials (even on VSTS github) that walk you through the steps for setting up your own agent, there are several missing points in almost all the tutorials. I will try to cover them up.
First things first, you will need a machine running Mac OSX (or later). Install following packages / applications -
Install XCode from Mac app store (https://itunes.apple.com/us/app/xcode/id497799835?ls=1&mt=12). If you want to stay on bleeding edge, dead over to https://developer.apple.com/download/ and download latest package and install it. I always recommend stable builds from Mac app store though.
Follow this article by Xamarin that demonstrates the setup and configuration of Xamarin on Mac OS - https://developer.xamarin.com/guides/ios/getting_started/installation/mac/
Homebrew is a package manager for Mac. It makes users' life easy with beautiful commands like brew install node
There are several packages that are required to be installed on build agent to be able to perform build steps hassle free. I could have shown you standard ways of installing these packages however if you are new user to Mac / Linux ecosystem you will find them quite difficult. Homebrew makes it easy like anything.
Copy this script -
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" |
Open Terminal and paste the script.
Hit "Return" when prompted and enter your user / system password (the script requires password for sudo access)
Wait for the script to do the magic, if all goes well. You will have Homebrew successfully installed on your machine.
Run brew list to confirm if homebrew is installed without any issue.
VSTS agent requires proper OpenSSL version before it can be successfully installed on your machine. Following steps will install / update OpenSSL version on your machine -
Copy and paste these commands in Terminal -
brew install openssl | |
brew link openssl --force |
brew install openssl will fetch latest OpenSSL package from internet and install it under usr/local (does not require sudo permission)
brew link openssl --force creates symlinks to installations you performed manually in Cellar. This allows you to have the flexibility to install things on your own but still have those participate as dependencies in homebrew formulas.
Copy and paste following commands in terminal -
brew install node |
Sit down and relax, brew a coffee maybe? To make sure you have Node and NPM installed, run two simple commands to see what version of each is installed: to see if Node is installed, type node -v and npm -v to see if NPM is installed in Terminal. Both the commands should print a version number of respective packages
The user we are going to use while setting up VSTS agent requires "administrative rights" to register a new tenant.
> The role is only needed to register the agent. A token is downloaded to listen to the queue. When a build is run, it will generate an OAuth token for the scoped identity selected on the general tab of the build definition. That token is short lived and will be used to access resource in VSTS. The account used to register the agent has no bearing on the build run time credentials
Download latest package of VSTS agent from VSTS Agent Releases | Github
~/$ mkdir vstsagent && cd vstsagent | |
~/vstsagent tar xzf ~/Downloads/vsts-agent-osx.10.11-x64-2.102.1.tar.gz |
Remember, if you have different **Downloads **folder, you need to change it in above command.
Run this command in terminal -
~/vstsagent ./config.sh |
The script expects some inputs from user like
>> Connect: | |
Enter server URL > https://{{your-tenant}}.visualstudio.com | |
Enter authentication type (press enter for PAT) > | |
Enter personal access token > **************************************************** | |
Connecting to server ... | |
Saving credentials... | |
>> Register Agent: | |
Enter agent pool (press enter for default) > | |
Enter agent name (press enter for mymachine) > myAgentName | |
Scanning for tool capabilities. | |
Connecting to the server. | |
Successfully added the agent | |
Enter work folder (press enter for _work) > | |
2016-05-27 11:03:33Z: Settings Saved. | |
Enter run agent as service? (Y/N) (press enter for N) > |
Run this command
~/vstsagent$ ./run.sh |
Open terminal and copy following command to start VSTS as a service.
$ ./svc.sh install | |
... | |
Creating runsvc.sh | |
Creating .Service | |
svc install complete |
$ ./svc.sh start | |
starting vsts.agent.rahulpp.Rahuls-Macbook-Pro | |
status vsts.agent.rahulpp.Rahuls-Macbook-Pro: | |
/Users/rahulpatil/Library/LaunchAgents/vsts.agent.rahulpp.Rahuls-Macbook-Pro.plist | |
Started: | |
25324 0 vsts.agent.rahulpp.Rahuls-Macbook-Pro: |
$ ./svc.sh stop | |
stopping vsts.agent.rahulpp.Rahuls-Macbook-Pro | |
status vsts.agent.rahulpp.Rahuls-Macbook-Pro: | |
/Users/rahulpatil/Library/LaunchAgents/vsts.agent.rahulpp.Rahuls-Macbook-Pro.plist | |
Stopped |
$ ./svc.sh status | |
status vsts.agent.rahulpp.Rahuls-Macbook-Pro: | |
/Users/rahulpatil/Library/LaunchAgents/vsts.agent.rahulpp.Rahuls-Macbook-Pro.plist | |
Started: | |
25324 0 vsts.agent.rahulpp.Rahuls-Macbook-Pro |
Once you successfully configure agent, you should see a folder structure similar to this -
Steps to confirm whether the build agent has successfully been configured with visualstudio.com tenant -
You can now configure build and release definitions for Xamarin iOS or Mac applications on this build agent.
Questions, feedback or comments are welcome through Comments :-)
Thanks, RP