microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.47k stars 2.6k forks source link

[Question]: How can I dynamically populate the options of a picklist #19789

Open yonatanNir opened 5 months ago

yonatanNir commented 5 months ago

Task name

No response

Task version

No response

Environment type (Please select at least one enviroment where you face this issue)

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

No response

Operation system

Ubuntu

Question

I got an Azure custom task written with Typescript. The task has a picklist defined in its task.json.

I want to be able to populate the options of the pick list based on the value picked on another picklist. 

Is there a way to do something like this pseudo code:

    const options1 = { option1: value1, option2: value2, option3: value3 }
    const options2 = { option1: othervalue1, option2: othervalue2, option3: othervalue3 }

    let mainChoice = tl.getInput("firstpicklist", true);
    let picklistObj = tl.getObject("secondPickList");
    if(mainChoice==="1")
    {
       picklistObj.options = options1;
    }
    else
    {
       picklistObj.options = options1;
    }

If there's no option to populate a direct object, is it possible somehow to take values from an Azure var group and have them as the options?
aleksandrlevochkin commented 4 months ago

Hi @yonatanNir, thank you for your question. I am not sure if it is possible to populate one picklist based on another using task-lib methods.

If you want to take values from an Azure variable group and populate a picklist with them, I think you can use dataSourceBindings to point your picklist to an endpoint, such as https://dev.azure.com/{org}/{project}/_apis/distributedtask/variablegroups. Please, refer to the ADO documentation,

yonatanNir commented 4 months ago

Hi @yonatanNir, thank you for your question. I am not sure if it is possible to populate one picklist based on another using task-lib methods.

If you want to take values from an Azure variable group and populate a picklist with them, I think you can use dataSourceBindings to point your picklist to an endpoint, such as https://dev.azure.com/{org}/{project}/_apis/distributedtask/variablegroups. Please, refer to the ADO documentation,

In order to meet the requirement of what I need to do, I need to be able to do 2 things:

1) Have some kind of event listener that is invoked every time an option is chosen in the pick list. 2) Set some kind of options object to the picklist to replace the previous ones with the new ones.

Are both things not possible with task-lib methods? Or maybe at least one of them is possible?

yonatanNir commented 4 months ago

Maybe only one of them is possible?