I'm trying to reuse some variable to generate the instructions of a ManualValidation@0 task.
The problem is that the task only seems to evaluate one "level" of variables, unlike for example the bash script.
My pipeline looks like this:
trigger:
- none
pool:
vmImage: 'windows-latest'
variables:
deploymentSlotName: 'preview-$(Build.BuildId)'
deploymentSlotUrl: 'https://mywebapp-$(deploymentSlotName).azurewebsites.net/'
stages:
- stage:
jobs:
- job: ConsoleStuff
steps:
- checkout: none
- bash: |
echo $(deploymentSlotName)
echo $(deploymentSlotUrl)
# This outputs:
# preview-214296
# https://mywebapp-preview-214296.azurewebsites.net/
- job: ConfirmStuff
pool: server
steps:
- task: ManualValidation@0
displayName: Confirm this
inputs:
notifyUsers: ''
instructions: 'SlotName: $(deploymentSlotName), SlotUrl: $(deploymentSlotUrl)'
# This actually outputs: SlotName: preview-$(Build.BuildId), SlotUrl: https://mywebapp-$(deploymentSlotName).azurewebsites.net/
If I change the task to look like this, I get the correct output:
- job: ConfirmStuff
pool: server
steps:
- task: ManualValidation@0
displayName: Confirm this
inputs:
notifyUsers: ''
instructions: 'SlotName: preview-$(Build.BuildId), SlotUrl: https://mywebapp-preview-$(Build.BuildId).azurewebsites.net/'
# This actually outputs: SlotName: preview-214296, SlotUrl: https://mywebapp-preview-214296.azurewebsites.net/
Is this a limitation of the task, or am I misunderstanding when the variables are evaluated?
Is there a nice way to do this, so I don't have to construct the same values multiple times?
I managed to use the original variables by setting them as output variables from a bash script, and then referencing them in the ConfirmStuff variables section, but that was a lot of code just to render a variable in a message.
Tested the same YAML sample and I can reproduce the same issue.
$(Build.BuildID)variable is a Runtime Variable. Refer to this doc: Predefined variablesWhen we use the nested variable contains the Runtime Variable(e.g.
$(Build.BuildID)), Agentless job task cannot parse nested variables directly.It can only parse the value of the first level of nested variables.
$(deploymentSlotName) = preview-$(Build.BuildId)This should be the limitation of the Agentless Job task.
To achieve your needs, we can only use Cross Stage variables for the time being.
For example:
Result:
On the other hand, if the nested variable uses a compile-time variable(e.g.
${{variables.['build.definitionname']}}), you can use the compile time variable format to define the variable:For example:
In this case, we can use the variable in agentless job task directly.