skip to Main Content

I’m traying to share a variable between a deploy job and a normal job in azure pipelines, when i try to print the variable im getting echo is off error.

Hey guys i´m having the next problem with azure pipelines

stages:

- stage: Stage
  jobs:
  - deployment: Staging
    displayName: Stage the WebApp
    environment: 
      name: 'Windows10'
      resourceName: Lxxxxxx
      resourceType: virtualMachine
    strategy:
      runOnce:
        deploy:
          steps:
          - powershell: echo "##vso[task.setvariable variable=myStageOutputVar;isOutput=true]variable"
            name: printvar

- stage: Swap
  dependsOn: Stage
  variables:
    myVarfromStage: $[ stageDependencies.Stage.Staging.outputs['Windows10.printvar.myStageOutputVar'] ]
  jobs:
  - deployment: Production
    displayName: Swap to production
    environment: 
      name: 'Windows10'
      resourceName: Lxxxxxx
      resourceType: virtualMachine
    strategy:
      runOnce:
        deploy:
          steps:
          - script: echo $(myVarfromStage)

and im getting the next log when running the pipeline

Starting: CmdLine
==============================================================================
Task         : Command line
Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version      : 2.231.1
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
Script contents: shell
echo 
========================== Starting Command Output ===========================
"C:WINDOWSsystem32cmd.exe" /D /E:ON /V:OFF /S /C "CALL "C:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.cmd""
ECHO is off.
Finishing: CmdLine

and if i want to do this between a deployment and a job how can i do it.

Appreciate.

2

Answers


  1. Use job.task.variable format instead of environment.task.variable for the outputs section in Swap stage.(Examples: Support for output variables)

    - stage: Swap
      dependsOn: Stage
      variables:
        myVarfromStage: $[ stageDependencies.Stage.Staging.outputs['Staging.printvar.myStageOutputVar'] ]
    

    Result:

    enter image description here

    Login or Signup to reply.
  2. trigger:
      branches:
        include:
          - "master"
      paths:
        include:
          - "azure-pipelines.yml"
    
    stages:
    
    - stage: Stage
      jobs:
      - deployment: Staging
        displayName: Stage the WebApp
        environment: 
          name: 'Windows10'
          resourceName: Lxxxxxx
          resourceType: virtualMachine
          # name: test
        strategy:
          runOnce:
            deploy:
              steps:
              - powershell: echo "##vso[task.setvariable variable=myStageOutputVar;isOutput=true]variable"
                name: printvar
    
    - stage: Swap
      dependsOn: Stage
      variables:
      - name: myVarfromStage
        value: $[ stageDependencies.Stage.Staging.outputs['Staging.printvar.myStageOutputVar'] ]
      jobs:
      - deployment: Production
        displayName: Swap to production
        environment: 
          name: 'Windows10'
          resourceName: Lxxxxxx
          resourceType: virtualMachine
          # name: test
        strategy:
          runOnce:
            deploy:
              steps:
              - script: echo $(myVarfromStage)
    

    enter image description here

    Docs reference.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search