0

I've got a pipeline with multiple jobs. For some reason, a variable that is set the stage is Null in a condition that is running from a job.

Here's the pipeline yaml:

https://github.com/ossentoo/azdo-yaml-varsdemo/tree/feature/private-agent

The syntax that i'm not expecting to evalutate to false is in the child.yml (line 24):

child yaml

I've attached one of the files from the log from Azure DevOps logs

In the log on line 73, this is shown:

Logs

The question is, why is variable applicationsList Null if the value is being set in the stage? I have tried changing syntax to variables.applicationsList, but that doesn't appear to work either.

thanks

thanks

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
ossentoo
  • 1,675
  • 2
  • 20
  • 44

1 Answers1

1

The problem is that the ${{ ... }} syntax is evaluated at compile time. At that point in time the value is still undefined.

Instead, you can use condition: $[ ... ]. That syntax will be evaluated at runtime.

See:

- ${{ each folder in parameters.folders }}:
  - deployment: ${{replace( folder ,'-','_')}}
    displayName: 'Apply ${{ folder }}'
    timeoutInMinutes: 480
    condition: $[contains(variables['applicationsList'], ${{folder}})]
jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • thanks Jesse. However, which line(s) in particular should I change to $[]? Do you mean the ${{}} surrounding the if statement? I take it that you mean the child.yml file is where the change should be made? If so, I'm not sure if that is valid yaml. Can you give me an example please using the code above? – ossentoo May 29 '21 at 10:57
  • Something like I posted above. You'll need to set a condition on the deployment job, instead of making it optional with an if. – jessehouwing May 29 '21 at 19:30
  • ok - thanks. Is there no way i can use the If statement? I prefer to have it so that, if a job is supposed to be disabled, it shouldn't show up at all in the browser.. If i use the condition, the job shows up in the browser (although it is disabled). – ossentoo May 30 '21 at 16:26
  • Not if you want to calculate/set the variable value at runtime. In that case, the variable must be available at the time the YAML template is parsed and compiled. If you pass the variable as in input (set at queue time), that may work. – jessehouwing May 30 '21 at 19:50