我有一个包含两个VM的环境,带有“ SQL”和“ APP”的标记,我希望有一个针对SQL vm的部署作业,并有一个步骤,创建一个输出变量,另一个针对“ APP” VM的部署作业应该能够在步骤中消耗它
答案 0 :(得分:2)
使用该变量的作业应使用--p这样的语法
$[dependencies.<job-name>.outputs['<lifecycle-hookname>_<resource-name>.<step-name>.<variable-name>']]
请考虑您具有名称为“ env-vm”的环境的场景
env-vm有两个已注册的虚拟机,标记为SQL的vm1和标记为APP的vm2。请参阅下面的示例,了解如何从部署作业中产生和使用输出变量
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