admin管理员组

文章数量:1277384

I'm working on an Azure DevOps Pipeline, and I'm having an issue where I'm unable to pass an output variable from a deployment job to a subsequent stage. Here's a simplified version of my pipeline YAML:

trigger:
- master

pool:
  vmImage: windows-latest

stages:
- stage: Deploy
  jobs:
  - deployment: DeployJob
    environment: 
      name: 'Local VM Deployment'
      resourceName: 'Resource-1'
      resourceType: VirtualMachine
    strategy:
      runOnce:
        deploy:
          steps:
          - task: PowerShell@2
            name: SetDeployResult
            inputs:
              targetType: 'inline'
              script: |
                Write-Host "Setting output variable"
                Write-Host "##vso[task.setvariable variable=DeployResult;isOutput=true]success"

- stage: PostDeployment
  dependsOn: Deploy
  jobs:
  - job: PostDeployJob
    variables:
      deployResult: $[ dependencies.Deploy.outputs['DeployJob.Deploy_Resource1.SetDeployResult.DeployResult'] ] 
    steps:
    - task: PowerShell@2
      inputs:
        targetType: 'inline'
        script: |
          Write-Host "The deploy result from the Deploy stage is $(deployResult)"
      displayName: 'Use Output Variable from Deploy Stage'

Problem:

In the PostDeployment stage, I’m trying to access the output variable DeployResult from the Deploy stage using the expression:

deployResult: $[ dependencies.Deploy.outputs['DeployJob.Deploy_Resource1.SetDeployResult.DeployResult'] ]

However, I am getting the following output:

Job preparation parameters
Variables:
  deployResult:
    Parsing expression: <dependencies.Deploy.outputs['DeployJob.Deploy_Resource1.SetDeployResult.DeployResult']> 
    Evaluating: dependencies['Deploy']['outputs']['DeployJob.Deploy_Resource1.SetDeployResult.DeployResult']
    Expanded: Null
    Result: '' 

It seems that the output variable DeployResult is not being set correctly, or there's an issue with how I'm referencing it. Could someone help me understand why this variable is not being passed correctly from the deployment job to the PostDeployment stage?

I'm working on an Azure DevOps Pipeline, and I'm having an issue where I'm unable to pass an output variable from a deployment job to a subsequent stage. Here's a simplified version of my pipeline YAML:

trigger:
- master

pool:
  vmImage: windows-latest

stages:
- stage: Deploy
  jobs:
  - deployment: DeployJob
    environment: 
      name: 'Local VM Deployment'
      resourceName: 'Resource-1'
      resourceType: VirtualMachine
    strategy:
      runOnce:
        deploy:
          steps:
          - task: PowerShell@2
            name: SetDeployResult
            inputs:
              targetType: 'inline'
              script: |
                Write-Host "Setting output variable"
                Write-Host "##vso[task.setvariable variable=DeployResult;isOutput=true]success"

- stage: PostDeployment
  dependsOn: Deploy
  jobs:
  - job: PostDeployJob
    variables:
      deployResult: $[ dependencies.Deploy.outputs['DeployJob.Deploy_Resource1.SetDeployResult.DeployResult'] ] 
    steps:
    - task: PowerShell@2
      inputs:
        targetType: 'inline'
        script: |
          Write-Host "The deploy result from the Deploy stage is $(deployResult)"
      displayName: 'Use Output Variable from Deploy Stage'

Problem:

In the PostDeployment stage, I’m trying to access the output variable DeployResult from the Deploy stage using the expression:

deployResult: $[ dependencies.Deploy.outputs['DeployJob.Deploy_Resource1.SetDeployResult.DeployResult'] ]

However, I am getting the following output:

Job preparation parameters
Variables:
  deployResult:
    Parsing expression: <dependencies.Deploy.outputs['DeployJob.Deploy_Resource1.SetDeployResult.DeployResult']> 
    Evaluating: dependencies['Deploy']['outputs']['DeployJob.Deploy_Resource1.SetDeployResult.DeployResult']
    Expanded: Null
    Result: '' 

It seems that the output variable DeployResult is not being set correctly, or there's an issue with how I'm referencing it. Could someone help me understand why this variable is not being passed correctly from the deployment job to the PostDeployment stage?

Share Improve this question asked Feb 24 at 6:21 Afnan AshrafAfnan Ashraf 3163 silver badges16 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Change to like as below which can work as expected:

stages:
- stage: Deploy
  jobs:
  - deployment: DeployJob
    environment:
      name: 'Local VM Deployment'
      resourceName: 'Resource-1'
      resourceType: VirtualMachine
    strategy:
      runOnce:
        deploy:
          steps:
          - pwsh: |
              Write-Host "Setting output variable"
              Write-Host "##vso[task.setvariable variable=DeployResult;isOutput=true]success"
            name: SetDeployResult

- stage: PostDeployment
  dependsOn: Deploy
  jobs:
  - job: PostDeployJob
    variables:
      deployResult: $[ stageDependencies.Deploy.DeployJob.outputs['Deploy_Resource-1.SetDeployResult.DeployResult'] ]
    steps:
    - checkout: none
    - pwsh: |
        Write-Host "The deploy result from the Deploy stage is $(deployResult)."
      displayName: 'Use Output Variable from Deploy Stage'

Related documentations:

  • Deployment jobs
  • Expressions

本文标签: Azure DevOps Pipeline Passing variables from a deployment job to another stageStack Overflow