6 minutes to read
In the past I have written about deploying with Visual Studio. This way we deployed our environments in the past. Since a couple of months we are using VSTS as we changed to a more DevOps way of working. I have looked into setting up VSTS when we first started with Visual Studio however I had difficulties to setup VSTS on my own by documentation that was available online, so I decided to share my experience from setting this up with my co-workers (thanks guys!!).
Connect Visual Studio Team Services to Visual Studio Code
Create your first project!
Create your account or login at https://visualstudio.com Setup your project
Now we have created our first project, we can start setting up our version control. I have chosen to connect Visual Studio Code to this project. To do so, I’ll first need to create a token in VSTS. You can find here how to create the token.
Get the URL to clone the VSTS repo
After you have created the token you can setup VS Code to integrate with VSTS. Copy the URL from the VSTS page and go to VS Code.
In VS Code open the Command Palette and type “Git: Clone”. Now paste the URL you copied. Next put in the local path on your computer where you would like to store the repository. Now you’ll be asked for the token to authorise against VSTS.
Source control from Visual Studio Code
Add the Azure Resource Managers files to VIsual Studio Code. After you have added the files go to source control type some info about the changes and hit the commit button.
Sync local repo to VSTS repo
Now we’ll need to upload the changes from our local repository to our repository in VSTS. On the bottom of the screen you’ll see the number 1 with an up arrow, click on it and the changes will be uploaded to VSTS.
Connect VSTS to your Azure subscription
From VSTS click on the gear icon and navigate to Services
Select services
From there we create a new Service Endpoint for Azure Resource Manager:
New Service Endpoint (ARM)
Create Azure Service Endpoint the easy way
As I am using the same account for VSTS as for Azure (where I am the owner of the subscription) I have permissions to create the Service Endpoint by VSTS. A new Azure Service Principal will be created in Azure Active Directory to make sure you can perform deployments.
Service Endpoint dialog
Create Azure Service Endpoint full version
If you are signed in to Visual Studio Team Services with another account then to Azure (for security reasons, or because you are using CSP for instance) you need to switch in the dialog box from the previous screenshot to the full version of the endpoint dialog.
Service Endpoint full dialog
Here you fill in all of the required details. For the Service Principal Client ID and Service Principal Key it is required to create an app registration in Azure Active Directory as described here.
Verify the connection and hit the OK button to save the ARM Service Endpoint.
Create Build pipeline
From the Build and Release menu go to Builds and choose to create a new definition. As we have saved our content in VSTS you should choose “VSTS Git” as your source.
Build select source
After you click on Continue click on “start with an empty process”.
Build start empty process
Now there is an empty build (CI) created. From here click on ‘+’ to add additional phases (tasks) to the build proces.
CI build created
When you are in the adding tasks search for “Publish Build Artifacts” and click on Add. Here you fill in the details – the only thing that really matters is the “Path to publish”. I have chosen to use the complete source directory “$(Build.SourcesDirectory)”. Now you can proceed and click on “Save & queue”, which will queue your first build.
Add additional build task
Create Release pipeline
From the menu we now choose Releases, where we create a new definition. Again we start with an empty process. Give your Environment a name and click on “1 phase, 0 task”
New Release with 0 tasks
We need to add an artifact so we have the content from the build process we can execute in the release pipeline. Click on Add artifact and select the Source (if this is your first setup, there should only be one) and click on Add.
Add artifact to the release pipeline
Just like in the creation of the build process we have to add a (or multiple) task(s) to the Release pipeline. Now we add “Azure Resource Group Deployment” (as we have a template and parameter JSON files).
Add task to release pipeline
Now the only thing left is to test the release pipeline. Head back to the releases main page and look for the created release pipeline (probably called New Release Definition). Click on “+ Release” followed by “Create Release” and click on Release.
Create Release
If the release was successful you can open your champagne! 🙂
Resources
- Using Version Control in VS Code
- Authenticate access with personal access tokens for VSTS
- Create identity for Azure app in portal
VS Code Extensions
- Azure Resource Manager Tools
- Azure Tools for Visual Studio Code
- Visual Studio Team Services
Have a cloudy day!