As it is not possible to pass a variable between stages in AzurePipeline, I'm trying to pass a variable between two jobs instead as it is explained in Azure documentation (https://docs.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch), however it wasn't successful and it returns an empty variable.
here is what I'm trying:
stages:
- stage: Deploy
jobs:
- deployment: A
displayName: TerraformDeploy
pool:
vmImage: 'ubuntu-latest'
environment: 'test'
strategy:
runOnce:
deploy:
steps:
- checkout: self
- task: Bash@3
displayName: 'Deploying Terraform'
inputs:
targetType: 'inline'
script: |
cd environments/test
terraform init
terraform apply -var 'client_id=$(client-id)' -var 'client_secret=$(client-secret)' -var 'key_data=$(LinuxSSHPubKey)' -var 'tenant_id=$(tenant-id)' -auto-approve
ip=$(terraform output public_ip_address)
echo $ip ###1.2.3.4
echo "##vso[task.setvariable variable=myPubIP;isOutput=true]$ip"
name: setvarStep
- job: B
dependsOn: A
pool:
vmImage: 'ubuntu-latest'
variables:
myIP: $[ dependencies.A.outputs['A.setvarStep.myPubIP'] ]
steps:
- task: AzureCLI@2
inputs:
azureSubscription: $(azureSubscription)
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
echo "ip:"$(myIP) ### Empty variable!!
I've tried so many different things for this case but it hasn't been fixed so far, can anyone help with this?
Updated:
It seems someone else is also reported this issue and they are planning to fix it:
Even if I use both jobs as normal job, it still doesn't work for my case..