I am developing a custom Azure DevOps extension that contains a custom pipeline task written in TypeScript. The source code when compiled produces JavaScript files in place next to their TypeScript equivalents.
The folder structure looks like:
/docs
/img
icon.png
/MyTaskNameV1
/node_modules
index.ts
index.js
My vss-extension.json includes the source folder and the contribution name:
{
// snip
"files": [
{
"path": "MyTaskNameV1"
},
{
"path": "docs/img",
"addressable": "true"
}
],
"contributions": [
{
"id": "mytaskname",
"type": "ms.vss-distributed-task.task",
"targets": [
"ms.vss-distributed-task.tasks"
],
"properties": {
"name": "MyTaskNameV1"
}
}
]
}
My task.json includes the version and execution entrypoint:
{
"$schema": "https://raw.githubusercontent.com/Microsoft/azure-pipelines-task-lib/master/tasks.schema.json",
"id": "...",
"name": "MyTaskName",
"version": {
"Major": 1,
"Minor": 0,
"Patch": 0
},
// snip
"execution": {
"Node16": {
"target": "index.js",
"argumentFormat": ""
}
}
}
I'd like to include a second version of the Task that includes newer input options in the task.json but I don't want to duplicate the source or increase the size of the extension. Ideally, I'd want one copy of the source code but use conditional logic in the task to activate newer features based on the version.
Something like:
import tl = require("azure-pipelines-task-lib/task");
async function run() {
// get version of the task
let version = ?
if (version == 1) {
// get v1 task inputs
} else {
// get additional v2 inputs
}
}
run();
My current tsconfig.json looks like this:
{
"compilerOptions": {
/* Language and Environment */
"target": "es2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
/* Modules */
"module": "commonjs", /* Specify what module code is generated. */
/* Emit */
"sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
// "outDir": "./", /* Specify an output folder for all emitted files. */
/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
/* Completeness */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}
My question is in two parts:
- How can my task determine which version of the task is running? Are there additional properties that I can pass in the contribution that I can discover at runtime? Is there a runtime variable that would contain my task's version?
- What changes do I need to introduce so that I can have two
task.jsonfiles?