Forum Discussion
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
- task: PowerShell@2
name: GetFunctionAppsToDeploy
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/*
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'a'
- deployment: Deployment
dependsOn: GetTemplateAndPar
condition: succeeded()
displayName: Deploy
environment: poc
strategy:
runOnce:
deploy:
steps:
- bash: |
"The value is $($[dependencies.GetTemplateAndPar.outputs['setVariable.varFuncAppsToDeploy'] ])"
1 Reply
- varunmittalCopper ContributorIt 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.