问题
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.
回答1:
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', "|");
来源:https://stackoverflow.com/questions/60993631/send-array-of-object-inside-custom-azure-devops-tasks-extensions