1

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 TARGET.

I'm not shure about where is my mistake, if in how I refer to the output variable to copy its value (stage vs. stageDependencies) or if the syntax for recovering the value of a variable in dependencies/stageDependencies ($(), $[] or ${{}}).

- 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).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.