Based on the feedback of @George Kosmidis to the answer of the original demander himself, I propose the following solution to decouple the hard dependency from the template to the calling pipeline:
--- template ---
parameters:
- name: dependentStage
type: string
stages:
- stage: Stage3
variables:
foo3: $[ stageDependencies.${{ parameters.dependentStage}}.Job1.outputs['step1.bar'] ]
dependsOn: [Stage1]
jobs:
- job:
steps:
- script: echo $(foo3)
--- main pipeline
stages:
- stage: Stage1
jobs:
- job: Job1
steps:
- task: powershell@2
inputs:
filePath: Tests/LoadData.ps1
- script: echo $(foo)
displayName: read foo
- bash: echo "##vso[task.setvariable variable=bar;isOutput=true]$(foo)"
name: step1
displayName: create public variable
- template: myTemplate.yml
parameters:
- dependentStage: Stage1