Authoring Azure DevOps Task — Development Environment (2)
I’ll explain how to create a development environment for Azure DevOps task. I’m using Visual Studio code for developing the environment.
I assume that you have already installed these libraries on the installation document.
Add a Build or Release Task
Add a custom build or release task in an extension for Azure DevOps Services
You can find the blog post about the Overview
Authoring Azure DevOps Task — Overview (1)
I want to share the resources, samples, and testing strategies on this blog post for someone who wants to author an…
What I want to achieve
For the task development project, I want a development environment like this.
- Run Unit Test with Coverage
- Generate JUnit and Coverage report
- Package and publish your extension
- CI / CD
Unit Test, Coverage, and Report
See this example. You can see how to configure the unit testing and coverage report on the Scripts section on the package.json. With mocha-JUnit-reporter library, you can generate the JUnit report by specifying the mocha parameter.
"compile": "tsc -p .",
"test": "tsc -p . & nyc mocha ./Test/L0.js",
"report": "tsc -p . & mocha ./Test/L0.js --reporter mocha-junit-reporter & nyc report"
Also, you can find the Coverage configuration. This configuration enables us to generate coverage report in .coverage_output/coverage directory with text, cobertura, and HTML format. Azure DevOps supports cobertura report. I recommend you to have it.
Enable SourceMap for debugging on the tsconfig.json. Then you can enable debug feature.
Enable Source Map with tsconfig.json
You can create a launch.json like this. Click debug icon on your Visual Studio Code.
You can find .vscode/launch.json as a result.
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0",
"name": "Mocha Tests",
"preLaunchTask": "Typescipt compile",
Create a custom task for compiling typescript source for help launch.json. It should reside in .vscode/tasks.json .
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
“label”: “Typescipt compile”,
“command”: “tsc -p .”
Tasks in Visual Studio Code
Expand your development workflow with task integration in Visual Studio Code.
Now you can debug your code.
Package your extension
Once you create your task, you need to test it with Azure DevOps. You have two ways to do it. One is to publish your extension with a newer version. The other is to upload your task only to a specific organization.
For debug purpose, I recommend the second way. If you use the first way, you need to bump the version number of the extension. If you frequently upload and test it, it increases the version number a lot.
Upload your task for testing
You can upload your task only to the specific organization by this command. You need personal access token of Azure DevOps. If you have an URL of Azure DevOps organization as “https://dev.azure.com/abc” then <<your AzureDevOps organization url>> will be “https://abc.visualstudio.com/DefaultCollection”.
tfx login -t <<your personal access token>> -u <<your AzureDevOps organization url>>
tfx build tasks upload --task-path <<your task directory>> --auth-type pat --overwrite
After testing it, you might want to pack your extension and publish to the market place. Bump your version of task.json and vss-extension.json of your extension and task. Then build an extension.
tfx extension create --manifest-globs vss-extension.json
deploy.bat copy the all js files, package.json, and node_modules to Task directory. Then tfx command creates vsix file which packages all the extension. You can upload through your market place portal. However, I recommend using the CI/CD for sharing your extension.
You can see the whole example in this repo.
Create a pull request comment if a CI is trigged by Pull Request. Install this extension to your project. Find the…
Azure Pipeline Build configuration
Configure these tasks as I show below.
You can see the coverage and test result.
We create a vsix file to upload the Market Place. Now we can
You can use Publish Extension
Azure DevOps Extension Tasks
This extension provides build and release tasks for packaging and publishing Azure Devops Extensions to the Visual…
Set the artifact as the build pipeline,
You can use two tasks.
For more details,
You might be required that configure connected service name. You need Personal Access Token of your account of Azure DevOps. It should be the same account as the Market Place users.
By default, it is published as a private extension. You can make it public to change your vss-extension.json
"galleryFlags": [ "Public" ],
Extension Manifest Reference
Every extension has a JSON manifest file which defines basic info about the extension and how it wants to extend and…
For example, you can refer my task.
You can't perform that action at this time. You signed in with another tab or window. You signed out in another tab or…
task.json has a preview flag
Azure DevOps task has semantic versioning system. The current version is automatically updated to your users. If you want to keep old version, you need to change the major version. You can control which version to use in here.
The version is included task.json and vss-extension.json.
Authoring Azure DevOps Task — Testing Strategy (3)
You can find a lot of official tasks here.