Written by Koen Maton, Microsoft ALM Consultant at eXsertus.
Today, Pieter Maertens ( SharePoint Consultant at eXsertus, read his blogpost here. ) and I spent some time to set up a Continuous Deployment Solution in the Cloud for SharePoint apps. We decided to use Team Foundation Service, Build Service and Office365 for this trial, so there is no need to set up one or more on-premises servers. This blog post is a walkthrough to enable you to set up automatic deployment of SharePoint apps to Office 365.
To start the exercise create a Team Project in Team Foundation Service, the hosted TFS 2012 Update 2 in the Cloud. You can find plenty of information about creating an account and start using the service on the World Wide Web (Check: tfs.visualstudio.com). Add all people who are working on this team project to the team in the project portal using their live account. Now all the added people have sufficient permissions to work on the project in TFS.
Besides the Team Project in TFS you also need a SharePoint environment because the goal is to deploy a SharePoint 2013 app automatically to this environment. Create such environment in the cloud using Office365. If you don’t have an office 365 subscription you can create and activate a 30-day trial by going to the Free Enterprise Trial site and fill in all the fields.
After successfully creating the office 365 portal your SharePoint online environment will be automatically provisioned. If everything is provisioned you can, but this is not obligatory, create a developer site. In this walkthrough we will, at first, be using the developer site because this enables us to easily deploy our apps from inside visual studio although the continuous deployment should be working on other sites as well.
With both environments configured, the time to create a new SharePoint 2013 App in Visual Studio has arrived. To create a new SharePoint 2013 App in Visual Studio 2012 you need to install at least Visual Studio 2012 and the additional “Office Developer Tools” on your local machine. Create a new “App for SharePoint 2013” which is SharePoint-hosted and add this project to the Source Control of your cloud environment of TFS.
You can read how to connect to a team project for the first time here in section Connect to a team project from team explorer. Don’t forget to perform a check-in of your code, otherwise nothing is added to Source Control.
At this point we have a SharePoint App solution stored in Team Foundation Service, and a working SharePoint environment in Office365. Next step is to use the Build Server in the cloud to set up automatic deployment of our solution to the SharePoint environment. Before you create a new Build Definition we recommend you to download the CodePlex project “Office / SharePoint 2013 Continuous Integration with TFS 2012”. This project contains BuildProcessTemplates, and PowerShell scripts that are customized already to help us with the continuous deployment. After downloading this project add the OfficeToolsAppTemplate.xaml file to the BuildProcessTemplates folder in the Source Control of your current Team Project.
The project from CodePlex also contains a folder named DeployScripts. Add the folder to Source Control in the same way you added the BuildProcesTemplate earlier. The scripts folder can be added directly in the root folder of the Team Project that you use as shown below.
Now it is time to create a new Build Definition to Build, Test and Deploy our new SharePoint 2013 App. Open Visual Studio 2012, go to your Team Explorer and navigate to Builds. Click on the New Build Definition link to create a new Build Definition. Give the new Build Definition a meaningfull self-describing name, and choose a preferred trigger for the build (Continuous Integration for continuous deployment, Manual when you want to trigger a deployment manually,…)
In the Build Defaults section you choose the Hosted Build Controller as Build Controller. This is the Build Controller in the Cloud, so no installation on a local server is needed. The online Build Server is configured in such a way that all needed components to deploy to an Office365 environment are available. In the Staging location option choose to copy build output to the server.
The last important section to configure the new Build Definition is the Process section. Select the OfficeToolsAppTemplate.xaml as the Build Process Template. This is the Template you’ve downloaded from CodePlex in one of the previous steps of this walkthrough.
In the parameters area of the process section of the Build Definition you specify the location of the SharePointAppDeploy.ps1 script, that is part of the download, as the deployment script that will be used. This script takes the output from the build, uninstalls an eventually earlier installed version of this app, and installs the new version in the specified SharePoint environment. All you have to do is provide a URL and credentials to connect to the SharePoint environment in the parameters.ps1 script in the same folder as the deployment script.
Now you can save your Build Definition and queue a new build to test your configuration. Right click in Team Explorer on the Build Definition, and choose Queue new build. A build is added to the build queue. You can follow the progress of the queued build by clicking View Builds.
When the build completed you see an indication that it succeeded, and the date that the build completed. Our build completed on April, 24th at 13h40.
The summary of this build indicates that our SharePoint 2013 App is installed successfully. This is shown in the Deployment Summary of the Build Report. You can always check the entire log of the build if you want more information about the activities executed during the build.
To make sure that the information in the Build Report is correct, browse to your SharePoint environment in Office365. Navigate to the developer website you created earlier in this walkthrough. In the Apps in Testing area you can see the app we created for this exercise. Click on the … link, and notice that the App was deployed on April, 23th at 13h4o. This indicates that the App was deployed during the build we triggered earlier.
In this walkthrough we describe the continuous deployment of a SharePoint 2013 App in a full cloud solution. The codebase is stored in Team Foundation Service 2012 where all other ALM features are also provided (we didn’t use them for this scenario because we wanted to focus on the automatic deployment part, but you can use them if you want).
The online Build Service picks up the source code, and deploys it automatically to an Office365 SharePoint environment. We worked on a basic solution this time to demo the features and show how it works, but in the future we will try to set up some more advanced scenario’s that can be more applicable than this one.
New blog posts will appear when new cases have been set up and tested, so keep on following us!