Azure管道中作业之间的传递变量

问题描述 投票:0回答:1

由于无法在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!!

我在这种情况下尝试了很多不同的方法,但到目前为止还没有解决,有人可以帮忙吗?

更新:

[似乎也有人报告了此问题,他们正计划解决此问题:

https://developercommunity.visualstudio.com/content/problem/769690/sharing-variables-between-jobs-not-working-for-dep.html

即使我同时使用这两项工作,但仍然不适用于我的情况。

variables azure-devops azure-pipelines
1个回答
0
投票

[不是非常确定这是上述YAML管道定义中的粘贴格式问题,并且我看到ip值已非常成功地生成,这似乎是由于您的YAML定义中name的语法不正确,所以它没有正确编译为reference name

© www.soinside.com 2019 - 2024. All rights reserved.