Storing script output as a list in azure devops build pipeline

Solution 1:

echo "##vso[task.setvariable variable=affectedApps;isOutput=true]${affectedApps}"

Above command is correct to set the variable, but as you have marked the isoutput to true, to use the same variable you will need to use $(stepname.variablename) expression. isoutput is used when you want to use the variable in subsequent jobs or stages. If you want to use the variable in subsequent steps/scripts tasks then do not set isoutput=true, then you can use the expression $(variableName) in subsequent steps

ref: https://docs.microsoft.com/en-us/azure/devops/pipelines/scripts/logging-commands?view=azure-devops&tabs=bash#examples-1

https://docs.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops#job-to-job-dependencies-within-one-stage