0

I am trying to get the new stage variables to work.Here is my stripped down example:-

stages:
- stage: firstStage
  jobs:
  - job: varSetJob
    pool: 
      vmImage: 'windows-latest'
    steps:
      - task: PowerShell@2
        inputs:
          targetType: 'inline'
          script: |

            Write-Output ("##vso[task.setvariable variable=DeployEnvironment;isOutput=true]AnEnvironment")
            Write-Output ("vso[task.setvariable variable=DeployEnvironment;isOutput=true]AnEnvironment")


        name: varStep

      - script: echo $(varStep.deployEnvironment)
        name: show

- stage: secondStage
  dependsOn: firstStage
  variables:
  - name: DeployEnvironmentstage
    value: $[ stageDependencies.firstStage.varSetJob.outputs['varStep.DeployEnvironment'] ]

  jobs:
  - job: showvar
    pool: 
      vmImage: 'windows-latest'
    steps:
      - script: echo $(DeployEnvironmentstage)
        name: show

This pipeline fails to start the second step and no logs are made, running in diagnostic mode.

build failure

I've checked the azure devops version and it is on the latest sprint version.

Has anyone had this working yet?

1 Answers1

1

Try to put the variables under a Job:

- stage: secondStage
  dependsOn: firstStage
  jobs:
  - job: showvar
    pool: 
      vmImage: 'windows-latest'
    variables:
      - name: DeployEnvironmentstage
        value: $[ stageDependencies.firstStage.varSetJob.outputs['varStep.DeployEnvironment'] ]
    steps:
      - script: echo $(DeployEnvironmentstage)
        name: show
Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39
  • This runs through. But I want the variable at stage scope to be able to set an environment name. At job scope it does not resolve. it creates and environment called "$(DeployEnvironmentstage)" – David Watson May 21 '20 at 13:46
  • Runtime expressions are designed to be used in the conditions of jobs. You need to put it under a job. – Cece Dong - MSFT May 22 '20 at 07:09
  • That is a shame It seems that there is no way to programmatically determine an environment during a pipeline run. My pipeline is multi-use in that it builds different editions depending on a setting or a script in the first job. The target environment is different per edition. – David Watson May 22 '20 at 09:00