Unleashing the full potential of Azure DevOps custom Tasks in VS Code and TypeScript: A guide to configuring input variables

Scenario: I have developed a custom build task for Azure DevOps.

  • This task requires an input parameter, param1
  • The task is created using VS Code (v1.30.1) and TypeScript (tsc --version state: v3.2.2)

Issue During debugging of the task, I am unable to provide variable values for param1. Breakpoints are being triggered which indicates that the debugging process is functioning correctly.

Snippet of 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();

The code runs successfully when executed from the console using tsc;node index.js. However, when trying to debug with the VS Code debugger, I encounter difficulties in passing a value to param1, resulting in a crash within the 'getInput' method.

My launch.json configuration:

{
"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 also attempted to add

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

under the output files section, but it did not yield desired results.

In further attempts, I tried utilizing

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

which also led to failure.

Additionally, I experimented with inputs in my tasks.json without success as mentioned in this SO Q&A (link)

Hence, my question arises: How can I pass in variable values while debugging Azure DevOps extensions in VS Code?

Answer №1

To ensure a Task input parameter passed as an environment variable functions correctly, it must be prefaced with INPUT_.

For instance, if you wanted to set the parameter param1 in the launch environment, your setup would look like this:

launch.json

"env": {
   "INPUT_param1": "thisVariable"
 }

It's important to note that there is no need to rename param1 in your code since the prefix will be automatically included when calling getInput().

Azure DevOps pipelines also add the prefix when configuring the task environment during runtime. This precaution helps minimize conflicts with other environment variables.

For more details on the Azure Pipelines Task SDK source, please refer to:
https://github.com/microsoft/azure-pipelines-task-lib/blob/master/node/task.ts#L219

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

ts-jest should replace the character '@' with the '/src' folder in the map configuration

I have set up a node project using TypeScript and configured various paths in my tsconfig.json file, such as: "paths": { /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl' ...

Using Angular: A guide to setting individual values for select dropdowns with form controls

I am working on a project that involves organizing food items into categories. Each item has a corresponding table entry, with a field indicating which category it belongs to. The category is represented by a Guid but displayed in a user-friendly format. C ...

The 'type' property is not present in the 'ChartComponent' type, however, it is necessary in the 'ApexChart' type

Encountered an error highlighted in the title: Property 'type' is missing in type 'ChartComponent' but required in type 'ApexChart'. Any attempt to resolve this issue led to another error message: Type '{ type: string; ...

Attempting to convert numerical data into a time format extracted from a database

Struggling with formatting time formats received from a database? Looking to convert two types of data from the database into a visually appealing format on your page? For example, database value 400 should be displayed as 04:00 and 1830 as 18:30. Here&apo ...

What is the best way to implement switchMap when dealing with a login form submission?

Is there a better way to prevent multiple submissions of a login form using the switchMap operator? I've attempted to utilize subjects without success. Below is my current code. import { Subject } from 'rxjs'; import { Component, Output } ...

Setting multiple values on a form can be accomplished by using the appropriate form fields

When it comes to setting values on fields, I am aware that I can choose between using setValue or patchValue However, I am currently encountering a situation where I need to avoid setting the value on each field individually. Take a look at my f ...

Calling a function within another function

In my code, I have a function that formats the price and retrieves the value needed for refactoring after upgrading our dependencies. I'm struggling with passing the form value to the amountOnBlur function because the blur function in the dependencie ...

Angular - Display shows previous and current data values

My Angular application has a variable called modelResponse that gets updated with new values and prints them. However, in the HTML, it also displays all of its old values along with the new ones. I used two-way data binding on modelResponse in the HTML [( ...

What are the steps to integrate a database into my Next.js application?

While I was experimenting with integrating postgresql into a nextjs project, I encountered an error 405 when trying to create an account. Below is the error message in the browser console: page.tsx:14 POST http://localhost:3000/api/auth/ ...

The development mode of NextJS is experiencing issues, however, the build and start commands are functioning normally

Just finished creating a brand new Next app (version: 12.0.7) using Typescript and Storybook. Everything seems to be working fine - I can successfully build and start the server. However, when I try to run dev mode and make a request, I encounter the follo ...

What is the process of substituting types in typescript?

Imagine I have the following: type Person = { name: string hobbies: Array<string> } and then this: const people: Array<Person> = [{name: "rich", age: 28}] How can I add an age AND replace hobbies with a different type (Array< ...

Tips for updating parameters that are defined in a controller within a promise

Currently, I am developing a single page application using Angular and TypeScript. I am facing an issue with updating the parameter value (_isShowFirst) of the controller inside a promise function. It seems like nothing is recognized within the promise blo ...

Strange behavior of the .hasOwnProperty method

When attempting to instantiate Typescript objects from JSON data received over HTTP, I began considering using the for..in loop along with .hasOwnProperty(): class User { private name: string; private age: number; constructor(data: JSON) { ...

How to remove a specific type from a generic type in Typescript without using Exclude<>?

I am looking for a solution to prevent my function from working with Moment objects when storing values in local storage. Currently, the function dynamically stringifies and stores values, but I want to exclude Moment objects from being processed. Here is ...

Search through an array of objects and assign a new value

I am facing a challenge with an array of objects structured as shown below: [ { "e_id": "1", "total": 0 }, { "e_id": "3", "total": 0 } ] My objecti ...

The type '{ domain: any; domainDispatch: React.Dispatch<any>; }' cannot be assigned to a type 'string'

Within my codebase, I am encountering an issue with a small file structured as follows: import React, { createContext, useContext, useReducer } from 'react' const initState = '' const DomainContext = createContext(initState) export co ...

Utilizing a syntax highlighter in combination with tsx React markdown allows for cleaner

I'm currently looking at the React Markdown library on Github and attempting to incorporate SyntaxHighlighter into my markdown code snippets. When I try to implement the example code within a function used for rendering posts, I encounter the error de ...

Converting JSON to string in Typescript is causing an error where type string cannot be assigned to type '{ .. }'

Here's the code snippet I'm working with: interface ISource extends IdModel { source_type_id: number; network_id: number; company_connection_id: number; feed_id: number; connection_id: number; feed_ids: number[]; name: string; tag ...

An error was encountered when attempting to reference an external JavaScript script in the document

Could someone please provide guidance on how to utilize the document method in an external .js file within Visual Studio Code? This is what I have tried so far: I have created an index.html file: <!DOCTYPE html> <html lang="en"> <head> ...

what kind of bespoke entity in TypeScript

Exploring typescript for the first time, I have constructed this object: const startingState = { name: { value: "", error: false }, quantity: { value: 0, error: false }, category: "Grocery& ...