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.

Prerequisite
I assume that you have already installed these libraries on the installation document.
You can find the blog post about the Overview
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
- Debugging
- Package and publish your extension
- CI / CD
Unit Test, Coverage, and Report
If you follow the installation notice , you will have mocha as a testing framework. If you want to have test coverage, you can use istanbul.
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.
"scripts": {
"compile": "tsc -p .",
"deploy": "Script\\deploy.bat",
"build": "Script\\build.bat",
"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.
"nyc": {
"extension": [
".ts"
],
"include": [
"Src"
],
"reporter": [
"text",
"cobertura",
"html"
],
"report-dir": "./.coverage_output/coverage",
"all": "true",
"check-coverage": true,
"statements": 70,
"functions": 70,
"branches": 70,
"lines": 70
},
Debugging
Enable SourceMap for debugging on the tsconfig.json. Then you can enable debug feature.
Enable Source Map with tsconfig.json
{
“compilerOptions”: {
“target”: “es6”,
“module”: “commonjs”,
“sourceMap”: true
}
}
Launch.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",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Mocha Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"preLaunchTask": "Typescipt compile",
"args": [
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/Test/L*.js"
],
"internalConsoleOptions": "openOnSessionStart"
}]
}
CustomTask
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
“version”: “2.0.0”,
“tasks”: [
{
“label”: “Typescipt compile”,
“type”: “shell”,
“command”: “tsc -p .”
}
]
}
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
Upload extension
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.
build.bat
call Script\deploy.bat
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.
CI/CD
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
Release pipeline
You can use Publish Extension
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.

Control exposure
By default, it is published as a private extension. You can make it public to change your vss-extension.json
"galleryFlags": [ "Public" ],
For example, you can refer my task.
task.json has a preview flag
"preview": true,
Versioning Strategy
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.