I have a pipeline with multiple jobs. I would like to send the output that I am setting in a powershell script to another job in the pipeline.
I have followed several examples to do this, like: 'https://medium.com/microsoftazure/how-to-pass-variables-in-azure-pipelines-yaml-tasks-5c81c5d31763' and 'https://devops.stackexchange.com/questions/17604/how-do-i-refer-in-azure-pipelines-to-an-output-variable-defined-in-a-previous-st'.
I can access the output variables that I am setting if the tasks are in the same job, but in different jobs the variables are empty.
This is my current pipeline:
- stage: DeploytoDev
displayName: Deploy to Dev
condition: ${{ eq(variables['Build.SourceBranch'], 'refs/heads/develop') }}
jobs:
- deployment: DeployInfraDev
environment: env
strategy:
runOnce:
deploy:
steps:
- task: AzureResourceManagerTemplateDeployment@3
displayName: 'Infra Deployment: Storage Account, Function App Develop'
inputs:
deploymentScope: 'Subscription'
azureResourceManagerConnection: '$(serviceConnectionDev)'
action: 'Create Or Update Resource Group'
subscriptionName: '$(subscriptionDev)'
resourceGroupName: '$(resourceGroup)'
location: '$(location)'
templateLocation: 'Linked artifact'
csmFile: '$(Pipeline.Workspace)/$(infraArtifactName)/templates/main.bicep'
overrideParameters: >-
-appName $(appName)
-stage dev
-location $(location)
deploymentMode: 'Incremental'
deploymentName: 'DeployPipelineTemplate'
deploymentOutputs: 'deploymentOutputs'
name: 'deployment'
- task: PowerShell@2
name: 'outputVariables'
displayName: 'Set Deployment Output Variables'
inputs:
targetType: inline
script: |
$armOutputObj = '$(deploymentOutputs)' | ConvertFrom-Json
$armOutputObj.PSObject.Properties | ForEach-Object {
$keyname = $_.Name
$value = $_.Value.value
# Creates a standard pipeline variable
Write-Output "##vso[task.setvariable variable=$keyName;isOutput=true]$value"
# Display keys in pipeline
Write-Output "output variable: $keyName $value"
}
Write-Output "##vso[task.setvariable variable=test;isOutput=true]test"
pwsh: true
- bash: echo "$(outputVariables.test) | $(outputVariables.storageAccountName)"
- job: BuildWebsite
dependsOn: DeployInfraDev
variables:
storageAccountName: $[ dependencies.DeployInfraDev.outputs['outputVariables.storageAccountName'] ]
storageAccountNameFoo: $[ dependencies.DeployInfraDev.outputs['outputVariables.test'] ]
steps:
- bash: echo "$(storageAccountName) | $(storageAccountNameFoo)"
- bash: echo "$storageAccountName | $storageAccountNameFoo"
env:
storageAccountName: $(storageAccountName)
storageAccountNameFoo: $(storageAccountNameFoo)
Image of the Bash inline scripts of the jobs:
Same job bash script:
Different Job without setting env variables in task
Different Job while setting env variables in task
I was expecting that in both bash scripts in the 'BuildWebsite' Job would print the same values as the bash script from the 'DeployInfraDev' Job.