Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
4 of 7 tasks
scholtz opened this issue Jan 2, 2025 · 2 comments
Closed
4 of 7 tasks

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

scholtz opened this issue Jan 2, 2025 · 2 comments
Assignees
Labels
Area: ABTT Akvelon Build Tasks Team area of work bug

Comments

@scholtz
Copy link

scholtz commented Jan 2, 2025

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)"
@scholtz scholtz added the bug label Jan 2, 2025
@v-schhabra v-schhabra added Area: ABTT Akvelon Build Tasks Team area of work and removed Area: Release labels Jan 6, 2025
@praval-microsoft
Copy link
Collaborator

praval-microsoft commented Jan 7, 2025

As mentioned in #20689

If you want to use the variables created in build stage, you need to add the dependency of build stage in your test stage like this

- stage: DeployTest
  displayName: Deploy Test Stage
  dependsOn: 
     - DeployDev
     - Build

This is not a bug and is mentioned in the documentation here Ref : FAQ

@scholtz Please give it a try and let me know if it resolves your issue.

@scholtz
Copy link
Author

scholtz commented Jan 9, 2025

@praval-microsoft thanks this solved the issue

@scholtz scholtz closed this as completed Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: ABTT Akvelon Build Tasks Team area of work bug
Projects
None yet
Development

No branches or pull requests

3 participants