4
votes

Background: I'm building a custom build task for Azure DevOps.

  • This task needs an input parameter, param1
  • It's written in VS Code (v1.30.1) and TypeScript (tsc --version state: v3.2.2)

Problem When I try to debug my task I can't pass in variable values for param1. Break points are hit so that part is working.

Some code: index.ts

import tl = require('azure-pipelines-task-lib/task');

async function run() {
   try {
      let param1: string = tl.getInput('param1', true);        
      if (param1 === null || param1 === undefined) {
        console.log('Should not be here...');
      }        
   }
   catch (err) {
      tl.setResult(tl.TaskResult.Failed, err.message);
   }
}
run();

This works fine when I run it from console with tsc;node index.js but when running with VS Code debugger I never seem to be able to pass a value to the param1 so it crashes inside the 'getInput' method.

My launch.json

{
"version": "0.2.0",
"configurations": [
    {
        "type": "node",
        "request": "launch",
        "name": "TaskName",
        "program": "${workspaceFolder}/Extensions\\BuildTasks\\TaskName\\index.ts",
        "outFiles": [
            "${workspaceFolder}/Extensions\\BuildTasks\\TaskName\\**\\*.js"
        ]
    }
]}

I've also tried to add

"env": {
   "param1": "thisBeString"
 }

under the output files, but no success.

In desperation I've also tried using

"args": {
   "--param1": "thisBeString"
}

with expected result (fail...)

I've also used inputs in my tasks.json to no success (according to this SO Q&A)

So Question is how do I pass in variable values when debugging Azure DevOps extensions in VS Code.

1
Does this help?Matt
@Matt did not help me, but may be my inexperience in VS Code+Typescript. But I can't add "args" to my tasks.json with type is typescript. Probably can be fixed by using a shell (node) type instead, but I can't get it to work :(Pierre

1 Answers

2
votes

The name of a Task input parameter passed as an environment variable must be prefixed with INPUT_.

In your example you would set the parameter param1 in the launch environment like so:

launch.json

"env": {
   "INPUT_param1": "thisBeString"
 }

You do not need to rename param1 in your code as the prefix is automatically added in the call to getInput().

The prefix is also added by Azure DevOps pipelines when setting up the task environment at runtime. Doing so helps reduce the risk of conflicts with other environment variables.

See here for the Azure Pipelines Task SDK source reference:
https://github.com/microsoft/azure-pipelines-task-lib/blob/master/node/task.ts#L219