'Azure pipeline EACH issue

I found a lot of examples about using EACH loop in an Azure pipeline, but all of them I found are using a parameter as the array. What about using an array that was created in the code? I mean:

  - script: COMMAND=$(npx nx affected:apps --base=$(BASE_SHA) --head=$(HEAD_SHA) --plain) && echo "##vso[task.setvariable variable=APPLICATIONS;]$COMMAND"

  - task: Bash@3
    inputs:
      targetType: 'inline'
      script: |
          echo 'APPLICATIONS + $(APPLICATIONS)'
          readarray -d ' ' -t ARRAYAPPS <<<'$(APPLICATIONS)'
          echo ${ARRAYAPPS[0]}
          echo ${ARRAYAPPS[1]}
  
  - ${{each APPLICATION in $APPLICATIONS }}:
  - task: ...


Solution 1:[1]

"If you're blocked in a way, try to change this way" I modified the approach, and I included the loop inside the bash script:

readarray -d ' ' -t ARRAYAPPS <<<$(APPLICATIONS)
if (( ${#APPLICATIONS[@]} > 0 )); then
  for (( i=0; i<${#APPLICATIONS[@]}; i++ ));
    ...

Solution 2:[2]

Pipeline ${{each does not support runtime pipeline variables. It only supports parameters, because the each is evaluated at compile time; and at that time, it is only parameters (and variables based on them) that are available.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tony
Solution 2 Vince Bowdren