由于无法在AzurePipeline的各个阶段之间传递变量,因此我正尝试在两个作业之间传递变量,正如Azure文档(https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch)所述,但未成功,并且返回一个空变量。
这是我正在尝试的内容:
stages:
- stage: Deploy
jobs:
- deployment: A
displayName: TerraformDeploy
pool:
vmImage: 'ubuntu-latest'
environment: 'test'
strategy:
runOnce:
deploy:
steps:
- checkout: self
- task: Bash@3
displayName: 'Deploying Terraform'
inputs:
targetType: 'inline'
script: |
cd environments/test
terraform init
terraform apply -var 'client_id=$(client-id)' -var 'client_secret=$(client-secret)' -var 'key_data=$(LinuxSSHPubKey)' -var 'tenant_id=$(tenant-id)' -auto-approve
ip=$(terraform output public_ip_address)
echo $ip ###1.2.3.4
echo "##vso[task.setvariable variable=myPubIP;isOutput=true]$ip"
name: setvarStep
- job: B
dependsOn: A
pool:
vmImage: 'ubuntu-latest'
variables:
myIP: $[ dependencies.A.outputs['A.setvarStep.myPubIP'] ]
steps:
- task: AzureCLI@2
inputs:
azureSubscription: $(azureSubscription)
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
echo "ip:"$(myIP) ### Empty variable!!
我在这种情况下尝试了很多不同的方法,但到目前为止还没有解决,有人可以帮忙吗?
更新:
[似乎也有人报告了此问题,他们正计划解决此问题:
即使我同时使用这两项工作,但仍然不适用于我的情况。
[不是非常确定这是上述YAML管道定义中的粘贴格式问题,并且我看到ip
值已非常成功地生成,这似乎是由于您的YAML定义中name
的语法不正确,所以它没有正确编译为reference name
。