3

I want to create a custom Task for Azure DevOps and I would like to have an array of object as parameters and use it like this in yaml:

data:
  - field1: "data1"
    field2: "data2"
  - field1: "data3"
    field2: "data4"

However I didn't found any avalable methods or examples for this kind of case, only simple array like string array. How an I pass a listof object from yaml to my custom Azure DevOps task? Feel free to ask me some more details if needed.

EDIT:

For example, I want to send a complexe lisf of object:

data:  # Data should be an array
  - object:
    file1: "/myDestinationPath"
    file2: "/TheFilePathToSend"
    override: true
  - object:
    file1: "/myDestinationPath2"
    file2: "/TheFilePathToSend2"
    override: false
...

Then I expect to load it, something like:

let dataArray = task.getPathInput('data', true);

Where dataArray can ba a simple JSON array, it will be easy to manage after.

2
  • Could you update with one simple sample data you want it stored at parameter, and how to you want this array map into task argument? Commented Apr 3, 2020 at 5:18
  • @MerlinLiang-MSFT I added an update :) Commented Apr 3, 2020 at 6:42

1 Answer 1

0

Fandro, a suggestion could be changing the way you organize your parameters and use taskgetDelimitedInput function.

Assuming you are using Azure pipeline task lib in TypeScript and familiarity with Build task creation.

Step 1) Define your variables using delimiter (e.g. | ) inside the task.json file.

    dataOrigin: "/myDestinationPath|/myDestinationPath2"
    dataDestination: "/TheFilePathToSend|/TheFilePathToSend2"
    dataOverwriteCriteria: "true|false"

Step 2) Edit your task file (e.g. index.ts ) you may use taskgetDelimitedInput, it returns the string array.

Step 3) Manipulate your values:

let dataOriginArray = task.taskgetDelimitedInput('dataOrigin', "|");
let dataDestinationArray = task.taskgetDelimitedInput('dataDestination', "|");
let dataOverwriteCriteriaArray = task.taskgetDelimitedInput('dataOverwriteCriteria', "|");
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer, it can be a solution, I also imagine a list of string arrays dirrectly as parameter. I m surprise there is no other options available
I agree you may you string array directly, anyway this is the available answer for the current version of the API and JSON definition. In case you think it is a great improvement you may create a pull request on github or even a feature request! Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.