
Let's dive into creating an Azure DevOps extension example with a step-by-step guide. The first step is to create a new project in Azure DevOps, which can be done by navigating to the Azure DevOps dashboard and clicking on the "New project" button.
To create a new project, you'll need to provide some basic information such as project name, description, and Git repository location. This is a crucial step as it sets the foundation for your extension.
In the Azure DevOps extension example, we'll be using the Azure DevOps SDK to create our extension. This SDK provides a set of APIs that allow us to interact with Azure DevOps services.
The Azure DevOps SDK is available for various programming languages, including C#, Node.js, and Python. This flexibility makes it easy to choose a language that fits your needs.
Curious to learn more? Check out: Azure Tokencredential C# Example
Prerequisites
To create Azure DevOps extensions, you'll need a few key tools and software. You'll need to create an Azure DevOps organization first.
You'll also need a text editor, and we recommend using Visual Studio Code, which offers features like intellisense and debugging support. You can download the latest version from the official website.
Node.js is another essential tool, and you should download the latest version to ensure compatibility with the production environment. Similarly, you'll need npmjs.com version 4.0.2 or newer, which includes the TypeScript Compiler.
To package your extension, you'll need to install the tfx-cli using npm, a component of Node.js. You can do this by running the command `npm i -g tfx-cli`.
You'll also need to install the Azure DevOps extension SDK, specifically the `azure-devops-extension-sdk` package.
Finally, you'll need a home directory for your project, which should have a specific structure after completing the steps in this article.
For more insights, see: Using Vscode for Azure Devops
Creating an Extension
Creating an extension in Azure DevOps involves several steps. First, you need to create a Publisher on the Visual Studio Marketplace, which requires a Publisher ID that you'll need later. This ID is crucial for publishing your extension.
Suggestion: Azure Mfa Nps Extension
To create your extension, you'll need to create task scaffolding, which includes setting up the folder structure, installing required libraries and dependencies, and adding a .gitignore file to exclude node_modules. You can use a PowerShell command to initialize a package.json file, and then install required modules like azure-pipelines-task-lib and TypeScript typings.
Here's a summary of the steps to create task scaffolding:
After creating the scaffolding, you can create a task.json file to describe your build/release task, which includes setting up the task's configuration options and scripts to execute at build/release time. This file is used by the build/release system to render configuration options to the user and know which scripts to execute.
Task Scaffolding
Creating an extension for Azure DevOps requires setting up a task scaffolding, which is the foundation of your task. This involves creating a folder structure, installing required libraries and dependencies, and configuring your task.json file.
You'll need to create a folder structure for your task and install the required libraries and dependencies. This includes installing azure-pipelines-task-lib, which is a library that provides a set of tools for building tasks.
To install azure-pipelines-task-lib, you'll need to run the command `npm install azure-pipelines-task-lib --save`. You'll also need to install TypeScript typings for external dependencies, such as `@types/node` and `@types/q`.
Here's a list of the required dependencies:
- azure-pipelines-task-lib
- @types/node
- @types/q
Once you've installed the dependencies, you'll need to create a .gitignore file and add node_modules to it. This will prevent node_modules from being checked into your repository.
You'll also need to install Mocha as a development dependency, which will allow you to write and run tests for your task. To install Mocha, run the command `npm install mocha --save-dev -g`.
Finally, you'll need to choose a version of TypeScript and create a tsconfig.json file to configure the compiler options. You can choose between TypeScript versions 2.3.4 and 4.6.3, and then run the command `tsc --init --target es2022` to create the tsconfig.json file.
Package Your
To package your extension, you'll need to create a VSIX file. This file is the package that will be uploaded to the Visual Studio Marketplace. You can create a VSIX file using the tfx-cli, which is a cross-platform command-line interface provided by Microsoft. To use the tfx-cli, you'll need to install it on your build agent.
A different take: Azure Devops Cli
The tfx-cli command to create a VSIX file is tfx extension create. You'll need to specify the manifest file and the revision version. The manifest file is a JSON file that contains metadata about your extension, and the revision version is used to track changes to your extension.
Here are the steps to create a VSIX file:
1. Install the tfx-cli on your build agent.
2. Run the command tfx extension create --manifest-globs vss-extension.json --rev-version to create the VSIX file.
3. The VSIX file will be created in the root directory of your extension.
Note that you'll need to update the version of your extension in the manifest file and the task version for the update to occur.
Here's a summary of the steps:
Once you have created the VSIX file, you can package your extension and publish it to the Visual Studio Marketplace.
Step 1: Create a Publisher
To create a publisher, start by going to the Microsoft Docs page that explains the setup process required for a Marketplace Publisher. This will walk you through the necessary steps.
The Microsoft Docs page is very helpful, so take some time to read through it. You'll need to note down the Publisher ID that you want to publish the extension under, as you'll need it later.
You can use an existing publisher, or create a new one. Either way, you'll need to keep track of that Publisher ID.
Publishing to Marketplace
To publish your extension to the Marketplace, you'll need to create a build and release pipeline on Azure DevOps. Install the Azure DevOps Extension Tasks extension to make this process easier.
Create a pipeline library variable group to hold the variables used by the pipeline. Declare the following variables: publisherId, extensionId, extensionName, and artifactName.
To maintain the custom task on the Marketplace, create a new Marketplace service connection and grant access permissions for all pipelines.
See what others are reading: Configure Pipeline in Azure Devops
Upload Your
To upload your extension to the Visual Studio Marketplace, you'll need to create a personal access token with the Marketplace (publish) scope. This token will be used to verify your authorization to publish the extension.
You can also upload your extension via the command line interface (CLI) using the tfx extension publish command. This command allows you to package and publish your extension in one step.
To use the tfx extension publish command, you'll need to specify the manifest-globs parameter to indicate the location of your manifest file. You can also use the --share-with parameter to share your extension with one or more accounts after it's published.
Here are the parameters you'll need to use:
- `--manifest-globs`: specifies the location of your manifest file
- `--share-with`: specifies the accounts to share your extension with
For example, you can use the following command to upload your extension:
```
tfx extension publish --manifest-globs your-manifest.json --share-with yourOrganization
```
Note that you'll need to replace `your-manifest.json` with the actual location of your manifest file, and `yourOrganization` with the actual name of your organization.
Mark as Paid
To mark your extension as paid, you'll need to add the Paid flag and __BYOLENFORCED tag to it. The Paid flag indicates that your extension is for sale on the Marketplace, while the __BYOLENFORCED tag specifies that the publisher is responsible for billing and licensing.

You'll also need to define a privacy policy, support policy, and an end-user license agreement for your paid extension. This is a requirement for all paid extensions in the Marketplace.
Publishers must provide content for the pricing tab in the Marketplace, including information on pricing and any trial periods offered. If your paid BYOL extension offers a trial period, you can specify the length of the trial in days.
Each paid extension requires a new section in the extension manifest to override paid licensing. This is a temporary measure until Microsoft removes the paid licensing check in the future.
To override paid licensing, you'll need to add an ID and a behavior to the manifest, matching the ID of the contributions defined in the manifest.
For another approach, see: Azure Devops License
Configuring and Testing
To configure and test your Azure DevOps extension, you'll need to add a custom script to your package.json file. This script will run your unit tests and publish the test results to Azure DevOps. You can do this by adding a "Use Node CLI for Azure DevOps (tfx-cli)" to install the tfx-cli onto your build agent.
Check this out: Azure Pipeline Script Step
You'll also need to set up your global SonarQube settings. This involves navigating to Administration > Configuration > General Settings > DevOps Platform Integrations, selecting the Azure DevOps tab, and clicking the Create configuration button. You'll need to specify your Azure DevOps collection/organization URL, a personal access token, and a configuration name.
To test your extension, you can install an extension that is shared with you. To do this, go to your organization control panel, select the project collection administration page, and find your extension in the "Extensions Shared With Me" group. Select the extension link and follow the installation prompts.
Global Settings
To set your global SonarQube settings, you need to navigate to Administration > Configuration > General Settings > DevOps Platform Integrations. Select the Azure DevOps tab and click the Create configuration button.
You'll need to specify the following settings:
- Configuration Name (Enterprise and Data Center Edition only): Use a succinct and easily recognizable name to identify your Azure DevOps configuration at the project level.
- Azure DevOps collection/organization URL: Provide your full Azure DevOps collection URL if you're using Azure DevOps Server, or your full Azure DevOps organization URL if you're using Azure DevOps Services.
- Personal Access Token: Use a dedicated Azure DevOps account with Administrator permissions, and obtain a personal access token with the scope authorized for Code > Read & Write for the repositories that will be analyzed.
This personal access token will be used to report your quality gate status to your pull requests. You'll need another personal access token for importing projects in the next section.
Broaden your view: Azure Devops Basic vs Stakeholder
Configure the Publish Task
To configure the publish task, you'll need to add the PublishVisualStudioExtension@3 task to your pipeline's YAML after the build task. This task is available in the Azure DevOps Extension Tasks.
You can install this extension by selecting it from the available task templates in the DevOps YAML editor. Once installed, edit the YAML of your pipeline and add the Publish Visual Studio Extension task.
Select the Marketplace connection added in Step 4, and use the default DevOps variable $(Build.SourcesDirectory) to get at the bin\release folder where the VSIX extension is placed by default. You can also use this variable to build a path to your manifest and VSIX extension files.
Here are the required inputs for the Publish Visual Studio Extension task:
Note that the VSIX File and Manifest File fields need to be paths, and you can use the default DevOps variable $(Build.SourcesDirectory) to build a path to these files.
The final YAML task will look something like this:
```yml
- task: PublishVisualStudioExtension@3
displayName: 'Publish Visual Studio Extension'
inputs:
vssPublish: 'true'
vssPublishFeed: 'your-feed-name'
vssPublishArtifactName: 'your-artifact-name'
vsixPath: '$(System.DefaultWorkingDirectory)/bin/Release/your-vsix-file.vsix'
manifestPath: '$(System.DefaultWorkingDirectory)/bin/Release/your-manifest-file.json'
marketplaceConnection: 'your-marketplace-connection-name'
```
Make sure to replace the placeholders with your actual values.
A different take: Azure Devops Recycle Bin
Install and Test
To install and test your Azure DevOps extension, you'll need to follow these steps. First, install an extension that's been shared with you in just a few steps: go to your organization's control panel, navigate to the project collection administration page, and find your extension in the "Extensions Shared With Me" group.
If you can't see the Extensions tab, make sure you're in the control panel and not the administration page for a project. To package and publish Azure DevOps Extensions to the Visual Studio Marketplace, you can download Azure DevOps Extension Tasks.
To set up a Service Connection, follow the instructions in Step 4: Set Up a Service Connection. This will allow you to run the command line Publish task through a Visual Studio Marketplace Service Connection and utilize the PAT to do the verification.
Here's a summary of the steps to install and test your Azure DevOps extension:
- Install an extension that's been shared with you.
- Set up a Service Connection.
- Download Azure DevOps Extension Tasks to package and publish your extension.
Discovery Attributes
Discovery attributes are a crucial part of making your extension discoverable in the marketplace. They help users learn about your extension and what it can do.
A good description is essential, and it should be no more than 200 characters. Think of it as your extension's elevator pitch - a couple of lines to make people want to install it. For example, "This extension helps you stay organized with a task timer and project management features."
You can also include icons to represent your extension, which should be in a dictionary format. The default icon should be 128x128 pixels and in a format such as BMP, GIF, EXIF, JPG, PNG, or TIFF.
Tags are another important discovery attribute, and they should be an array of string tags to help users find your extension. For example, "agile", "project management", and "task timer" are all relevant tags.
Screenshots are also valuable, and they should be an array of images that couldn't be included in your content. Each image should be 1366x768 pixels, and the path of each item should be the path to the file in the extension.
Here's a quick reference guide to discovery attributes:
By including these discovery attributes, you'll make it easier for users to find and understand your extension, which will ultimately make it more successful.
Advanced Topics
Azure DevOps extensions can be used to integrate third-party tools and services into the Azure DevOps platform.
One such extension is the Azure Pipelines extension, which allows users to integrate their Azure Pipelines with other tools and services.
The Azure Pipelines extension can be used to automate tasks such as deploying code to Azure App Service.
With this extension, users can create custom deployment steps and integrate them with their Azure Pipelines.
The Azure DevOps extension marketplace has a wide range of extensions available, including the popular GitHub extension.
The GitHub extension allows users to connect their GitHub repositories to Azure DevOps and manage their code in one place.
This integration enables users to view GitHub issues and pull requests directly within Azure DevOps.
Users can also use the Azure DevOps extension to integrate their Azure DevOps projects with other Microsoft tools such as Visual Studio Team Services.
This integration enables users to manage their projects and teams across multiple tools and platforms.
The Azure DevOps extension can also be used to integrate with other third-party tools and services such as Slack and Trello.
You might enjoy: What Is Azure Devops Used for
Pipeline and Tasks
Creating a pipeline and tasks in Azure DevOps is a crucial step in publishing your extension to the Marketplace. To create a task scaffolding, you need to create a folder structure for the task, install the required libraries and dependencies, and add the Azure Pipelines Task Library. This involves running `npm init`, installing `azure-pipelines-task-lib`, and adding TypeScript typings for external dependencies.
To create a task, you need to add a `task.json` file in the buildandreleasetask folder, which describes the build/release task and is used by the build/release system to render configuration options to the user and execute scripts at build/release time. This file includes placeholders for task information, such as `taskguid`, `taskname`, and `taskauthor`.
When creating a build and release pipeline to publish your extension to the Marketplace, you need to install the Azure DevOps Extension Tasks extension in your organization, create a pipeline library variable group to hold the variables used by the pipeline, and declare variables such as `publisherId`, `extensionId`, and `extensionName`.
Here's an interesting read: Azure Devops Triggers
In Azure Pipelines, you can construct a pipeline for Gradle or Maven by adding a Prepare Analysis Configuration task before your build task, editing or adding a new Maven or Gradle task, and adding a Publish quality gate Result on your build pipeline summary. For .NET projects, you need to add a Prepare Analysis Configuration task, a Run Code Analysis task, and a Publish quality gate Result on your build pipeline summary. For C family projects, you need to make the Build Wrapper available on the build agent, add a Prepare analysis configuration task, a Command Line task to run your build, and a Run code analysis task to run the code analysis.
To add a Visual Studio Extension publishing task to your pipeline, you need to install the Azure DevOps Extension Tasks tool, add and configure the Publish Task, and use the default DevOps variable $(Build.SourcesDirectory) to get at the bin\release folder where the VSIX extension is placed by default. The final YAML task for the Publish Visual Studio Extension task includes the paths to the VSIX file and manifest file.
You might like: Azure Devops Pipeline Extends
Quality Gate and Analysis
Automatic branch detection is only available when using Git, so if you're working with Git repositories, you're in luck.
You can configure branch analysis by using the Prepare analysis configuration, Run code analysis, and Publish quality gate result tasks in your build definitions.
The Prepare analysis configuration task is required to set up the necessary settings before executing the build. For more details, see the Using the Prepare Analysis Configuration task article.
The Run code analysis task executes the analysis of source code, and you can specify which version of Java to use for analysis. The options are:
The Publish quality gate result task displays the quality gate status in the build summary, letting you know if your code meets quality standards for production.
To ensure all of your pull requests get automatically analyzed, add a build validation branch policy on the target branch.
A different take: Azure Devops Branch Policies
Preventing pull request merges when the quality gate fails can be achieved by adding a SonarQube/quality gate status check branch policy on the target branch. This will prevent the merge of pull requests with a failed quality gate.
However, projects configured as part of a monorepo cannot use this status check branch policy to prevent pull request merges.
Recommended read: Azure Devops Parallelism Request
SonarQube Integration
To integrate SonarQube with Azure DevOps, you need to import your Azure DevOps repositories into SonarQube. This allows you to create SonarQube projects from your Azure DevOps repositories.
To set up the import, you need to set your global DevOps platform settings and add a personal access token for importing repositories.
You can add a project from Azure DevOps by clicking the Add project button in the upper-right corner of the Projects homepage and selecting Azure DevOps.
To use SonarQube with Azure DevOps, you also need to declare your SonarQube server as a service endpoint in your Azure DevOps project settings.
Related reading: Azure Devops Project Timeline
Here are the steps to add a new SonarQube service endpoint:
- In Azure DevOps, go to Project Settings > Service connections.
- Select New service connection and then select SonarQube from the service connection list.
- Enter your SonarQube Server URL, an authentication token, and a memorable Service connection name. Then, select Save to save your connection.
Gradle and Maven Pipelines
To set up a Gradle or Maven pipeline in Azure DevOps, you need to follow these steps. First, create or edit a Build Pipeline and add a new Prepare Analysis Configuration task before your build task. This is crucial for a successful pipeline.
Next, edit or add a new Maven or Gradle task to your pipeline. This will allow you to build your project using either Maven or Gradle.
To publish the quality gate result, add a new Publish quality gate Result on your build pipeline summary. This will show the result of your quality gate analysis.
Under the Triggers tab of your pipeline, select Enable continuous integration and choose all of the branches for which you want SonarQube analysis to run automatically. This will enable continuous integration for your pipeline.
Here's a summary of the steps to set up a Gradle or Maven pipeline:
- Create or edit a Build Pipeline and add a new Prepare Analysis Configuration task.
- Edit or add a new Maven or Gradle task.
- Add a new Publish quality gate Result on your build pipeline summary.
- Under the Triggers tab, select Enable continuous integration and choose the desired branches.
- Save your pipeline.
NET Pipelines
To set up a .NET pipeline in Azure DevOps, you'll need to follow these steps: create or edit a Build Pipeline, add a new Prepare Analysis Configuration task before your build task, add a new Run Code Analysis task after your build task, add a new Publish quality gate Result on your build pipeline summary, and enable continuous integration under the Triggers tab.
To do this, go to the Triggers tab of your pipeline and select Enable continuous integration, then choose all of the branches for which you want SonarQube analysis to run automatically.
Here's a quick rundown of the necessary tasks in the correct order:
- Prepare Analysis Configuration
- Build
- Run Code Analysis
- Publish quality gate Result
C Family Pipeline
To create a C family pipeline in Azure, you'll need to follow a specific order of steps. These steps can be interwoven with other build steps as long as the order is followed.
First, make the Build Wrapper available on the build agent by downloading and unzipping it, depending on the platform of the host. The archive to download and decompress will vary based on the agent OS.
To configure the Prepare analysis configuration task, click on the Prepare analysis on SonarQube task to configure it. This task is crucial for setting up the analysis configuration.
You'll also need to add a Command Line task to run your build, as the analysis can only happen if the build is run through a command line. This will allow the build wrapper to wrap up the build.
After the build, add a Run code analysis task to run the code analysis and make the results available to SonarQube. This task should be run right after the previous one, as the build environment should not be significantly altered before running the analysis.
Finally, add a Publish quality gate result task to publish the quality gate result.
Here's a summary of the steps in order:
- Make the Build Wrapper available on the build agent
- Prepare analysis configuration task
- Command Line task to run the build
- Run code analysis task
- Publish quality gate result task
Frequently Asked Questions
What are Azure DevOps extensions?
Azure DevOps extensions are customizable add-ons written in standard web technologies like HTML, JavaScript, and CSS, allowing you to tailor your experience. They're developed using your preferred tools, making it easy to extend and enhance your Azure DevOps capabilities.
Sources
- https://tobiasfenster.io/azure-devops-simplify---the-community-extension-to-work-more-efficiently-with-azure-devops-from-vs-code
- https://learn.microsoft.com/en-us/azure/devops/extend/develop/add-build-task
- https://docs.sonarsource.com/sonarqube/10.5/devops-platform-integration/azure-devops-integration/
- https://intellitect.com/blog/demystified-azure-pipeline-vsix-extension/
- https://learn.microsoft.com/en-us/azure/devops/extend/develop/manifest
Featured Images: pexels.com