Skip to content

[BUG]: Variables are destroyed after first use #20762

Closed
@scholtz

Description

New issue checklist

Task name

No response

Task version

No response

Issue Description

We want to create variable in the build stage and use the variable in all deployment stages.

We are able to create variable in the first stage, and pass it to the dev environment. We are able to store variable in dev environment and pass it to test environment. But we are not able to pass the variable from the build stage to dev stage and the same variable to the test stage. It looks like the variable is removed after the first usage.

Related to #20689

Environment type (Please select at least one enviroment where you face this issue)

  • Self-Hosted
  • Microsoft Hosted
  • VMSS Pool
  • Container

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

No response

Operation system

ubuntu

Relevant log output

Received variable from build: 
Received variable from Dev: Hello from Build

Full task logs with system.debug enabled

build-stage.txt
dev-stage.txt
test-stage.txt

test-stage-full.txt
dev-stage-full.txt
build-stage-full.txt

Repro steps

trigger:
- none

stages:
- stage: Build
  displayName: Build Stage
  jobs:
  - deployment: BuildJob
    displayName: Build Job
    environment: "Dev"
    strategy:
      runOnce:
        deploy:
          steps:
          - script: |
              echo "##vso[task.setvariable variable=myVar;isOutput=true]Hello from Build"
            name: OutputStep

- stage: DeployDev
  displayName: Deploy Dev Stage
  dependsOn: Build
  variables:
    myVarFromBuild: $[ stageDependencies.Build.BuildJob.outputs['BuildJob.OutputStep.myVar'] ]
  jobs:
  - deployment: DeployJob
    displayName: Deploy to Dev
    environment: "Dev"
    strategy:
      runOnce:
        deploy:
          steps:
          - script: |
              echo "Received variable from Build: $(myVarFromBuild)"
              echo "##vso[task.setvariable variable=myVarDev;isOutput=true]$(myVarFromBuild)"
            name: SetOutputForDev

- stage: DeployTest
  displayName: Deploy Test Stage
  dependsOn: DeployDev
  variables:
    myVarFromBuild: $[ stageDependencies.Build.BuildJob.outputs['BuildJob.OutputStep.myVar'] ]
    myVarFromDev: $[ stageDependencies.DeployDev.DeployJob.outputs['DeployJob.SetOutputForDev.myVarDev'] ]
  jobs:
  - deployment: DeployJob
    displayName: Deploy to Test
    environment: "Test"
    strategy:
      runOnce:
        deploy:
          steps:
          - script: |
              echo "Received variable from build: $(myVarFromBuild)"
              echo "Received variable from Dev: $(myVarFromDev)"

Metadata

Labels

Area: ABTTAkvelon Build Tasks Team area of workbug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions