I'm writing an Azure Pipeline where I use the
targetBranchName of a pull request to define the test environment I'm going to use. Since
targetBranchName has no value before execution, I created a "prepare" stage where I capture the value of the variable to use in further stages.
- stage: prepare jobs: - job: variables steps: - checkout: none - powershell: Write-Output "##vso[task.setvariable variable=TARGET;isOutput=true;isReadOnly=true]$(system.pullRequest.targetBranchName)"
Then, in a later stage, I want to use the output variable
BRANCH_NAME to find whether the stage should run and if so to load the appropriate group variables. I also would like to capture the value of the output variable in a job variable so that I can refer to it with a more "convenient" name.
The stage condition seems to be working when tested with manually set values for
TARGET in the
prepare job, but I can't actually see the value of
TARGET, so I added a "print" step and it shows no value for
I'm not shure about where is my mistake, if in how I refer to the output variable to copy its value (
stageDependencies) or if the syntax for recovering the value of a variable in
- stage: deploy_to_cint dependsOn: prepare condition: and(succeeded('prepare'), in(dependencies.prepare.outputs['variables.environment.TARGET'], 'env1', 'env2')) variables: - name: TARGET value: $(dependencies.prepare.outputs['variables.environment.TARGET']) - group: 'EnvironmentCredentials-$(TARGET)' jobs: - job: debug steps: - bash: echo This is running for $(TARGET).