0

I have a environment with two VMs, tagges with "SQL" and "APP", I would like to have deployment job targeting SQL vm and having step, creating a output variable, another deployment job targeting "APP" VM should able to consume it in its step

  • Welcome to Stack Overflow! What have you already tried to achieve your solution? It is expected of askers to show research efforts. – Filnor May 14 '20 at 09:41

1 Answers1

3

Reference doc

Job consuming the variable should use syntax like -

$[dependencies.<job-name>.outputs['<lifecycle-hookname>_<resource-name>.<step-name>.<variable-name>']]

Consider a scenario you have environment with name "env-vm"

env-vm has two vms registered with it, vm1 with tag SQL and vm2 with tag APP. refer below sample for how to produce and consume the output variable from deployment job

jobs:
- deployment: producer
  environment:
    name: env-vm
    resourceType: VirtualMachine
    tags: SQL
  strategy:
    runOnce:
      deploy:
        steps:
        - script: echo "##vso[task.setvariable variable=myOutputVar;isOutput=true]this is the deployment variable value"
          name: setvarStep
        - script: echo $(setvarStep.myOutputVar)
          name: echovar

- deployment: consumer_deploy
  dependsOn: producer
  variables:
    myVarFromDeploymentJob: $[ coalesce(dependencies.producer.outputs['deploy_Vm1.setvarStep.myOutputVar'], 'fubar') ]
  environment: 
    name: env-vm
    resourceType: VirtualMachine
    tags: APP
  strategy:
    runOnce:
      deploy:
        steps:
        - script: "echo $(myVarFromDeploymentJob)"
          name: echovar