Build and Release Task for Extensions of Visual Studio Team Services (VSTS)
Posted by: Gouri Sohoni
in Category VSTS & TFS
Abstract: Create a Build Task that automates package, publish, share and installation of a VSTS extension.
A previous article Create a VSTS Extension that uses Azure Functions explained a step by step process to create VSTS Extension, package into .vsix file, publish to Visual Studio Marketplace, Share the extension to VSTS Account and finally install it. In this article, we will use the already created extension and use a Build Task that automates package, publish, share and installation of the extension.
- VSTS account
- Already created package for extension .vsix file
- Personal Access Token (PAT) for Endpoint (discussed later in the article)
Build and Release Tasks for Extensions
Let us first Install “Build and Release Tasks for Extensions” task from this url. This task includes Package, Publish, Share, Install and Query Version. When we give an extension and the manifest file to that task, the package will be created. We can also provide an already existing package i.e. the .vsix. The extension can be published either privately or publicly. The extension can be shared with one or more VSTS accounts and installed. We can even query version of an already existing VSTS extension.
The curious thing is that this task itself is bundled to form another extension which we can install for a particular VSTS account.
Click on Install. The installation wizard will prompt you to specify which VSTS account should this extension be available to.
After clicking on the continue button, confirm the account name
The next step is to go to the account and confirm that this extension is actually available.
Personal Access Token for Marketplace
Now that the extension is available, we need to create PAT (Personal Access Token) endpoint for the Marketplace, and finally a build definition which uses this extension.
Let us see how to create a Personal Access Token. Select ‘Security’ menu item from the VSTS account’s drop down menu for account owner.
Select Personal Access Token and click on Add
Now provide a description, select the number of days the token should be active, and select “All Accessible Accounts”. Even though you may want to apply it to a single VSTS account, the task that we are targeting requires the PAT for “All Accessible Accounts”. Selecting “All accessible accounts” is a very important step because if you select it only for the current account, the build will fail later. The Scope can be set for the Marketplace (Publish).
Once you click on the Create Token button, a token will be displayed. Remember to copy it as you cannot access it later which publishing the extension.
Upload the working .vsix file which later can be provided with the task configuration. To do so, open the team project that you are working on and click the code menu item. You will see the link to ‘Upload existing files’. When you select browse, a dialog box to select and upload the file will open.
Now that all preliminaries are done, it is time for actual publishing of VSTS extension.
Publishing VSTS Extension
Start with an empty build definition if there is no code to build or test to be executed. Add the task of “Build and Release Tasks for Extensions” and configure it.
For configuration, we need to create an endpoint. Click on Manage for a Marketplace connection.
Select Marketplace to create a new endpoint, enter the name and provide the PAT you have already copied.
Once the endpoint is ready, you need to provide the path to .vsix file (which has already been uploaded).
Publisher ID, Extension ID, Extension Name and Extension Version will be kept as available in the package.
In case we need to change the values, we can provide them with extension name and extension version which will be overridden. Queue the build and the extension will be published on the publishers’ page. We can view it at https://marketplace.visualstudio.com/manage/publishers\
In case we want to share the extension to one or more VSTS instances, we can provide the list in Share with textbox at the time of configuration. Ensure to enter only the account name for sharing. If you do any changes to the build definition and trigger the build, make sure to change the version number for the extension. If you forget this step, you will get an error that says the same version number cannot be uploaded.
When we install “Build and Release Tasks for Team Services”, we get two more steps named Query Extension and Share Extension similar to Publish Extension.
We can use the step for Query Extension Versions to find out the version for any extension. We should know the publisher id and extension id in order to execute this.
The installation of the extension to accounts will be taken care of by the Share Extension task. This task can be configured to provide either the .vsix file or providing the extension and publisher id.
In this article, we explored another way of publishing and sharing a VSTS extension.