Forum Discussion

vishalb535's avatar
vishalb535
Copper Contributor
Jan 23, 2023

Unable to get output variable value in the deploy stage

Hi,

 

I am trying to fetch variable value in deployment stage but I am unable to get variable value

 

 

trigger: none

jobs:

-job: GetTemplateAndPar

 

  - taskPowerShell@2

    nameGetFunctionAppsToDeploy

    inputs:

      targetType'inline'

      script: |

        New-Item -Path '$(Build.ArtifactStagingDirectory)/$(serviceName)/deploy' -ItemType Directory

        Expand-Archive -Path '$(Build.ArtifactStagingDirectory)/*.zip' -DestinationPath '$(Build.ArtifactStagingDirectory)/$(serviceName)/unziped'

        $folders = (Get-ChildItem -Directory $(Build.ArtifactStagingDirectory)/$(serviceName)/unziped).Name

        Write-Host "##vso[task.setvariable variable=varFuncAppsToDeploy;isOutput=true;]$folders"

        foreach ($folder in $folders)

        {

            Compress-Archive -Path $(Build.ArtifactStagingDirectory)/$(serviceName)/unziped/$folder/* -DestinationPath $(Build.ArtifactStagingDirectory)\$(serviceName)\deploy\$folder.zip

        }

         

          

            Write-Host "$(Build.ArtifactStagingDirectory)\$(serviceName)\deploy\$folder.zip"

            Get-ChildItem -Path $(Build.ArtifactStagingDirectory)/$(serviceName)/unziped/$folder/*

            

  - taskPublishBuildArtifacts@1

    inputs

        PathtoPublish'$(Build.ArtifactStagingDirectory)'

        ArtifactName'a'

    

  

deploymentDeployment

  dependsOnGetTemplateAndPar

  conditionsucceeded()

  displayNameDeploy

  environmentpoc

  strategy:

    runOnce:

     deploy:

       steps

 

             - bash: |

                        "The value is $($[dependencies.GetTemplateAndPar.outputs['setVariable.varFuncAppsToDeploy'] ])"

             

               

        

    

 

 

1 Reply

  • varunmittal's avatar
    varunmittal
    Copper Contributor
    It looks like you are trying to access the value of the variable "varFuncAppsToDeploy" in your deployment stage, which was set in the previous job "GetTemplateAndPar" using the PowerShell task.
    In order to access the variable in the deployment stage, you need to reference it using the correct syntax.

    In your deployment stage, you can use the following syntax to access the variable:
    $(dependencies.GetTemplateAndPar.outputs['setVariable.varFuncAppsToDeploy'])

    You can also use the following way of accessing it
    $(varFuncAppsToDeploy)

    Note that the variable must be marked as an output variable using the "isOutput=true" flag in the PowerShell script, as you have done in your script.
    You might also need to check the pipeline's log files to see the variable's value and if it's being set or not.
    Also make sure that you are running the bash task in the same agent where the variable was set.