Skip to content

Instantly share code, notes, and snippets.

@rudfoss
Created January 29, 2021 07:34
Show Gist options
  • Save rudfoss/4532f341e9c276726e6e95ea28b2c573 to your computer and use it in GitHub Desktop.
Save rudfoss/4532f341e9c276726e6e95ea28b2c573 to your computer and use it in GitHub Desktop.
This gist shows how to use variables defined in one deployment job in another with the runOnce strategy.
name: TEST-$(Date:yyyyMMdd)-$(Build.BuildId)
trigger: none
parameters:
- name: env
type: string
default: 'test'
variables:
- name: vmImage
value: 'ubuntu-latest'
readonly: true
stages:
- stage: StageA
jobs:
- deployment: JobA
environment: $(env)
pool:
vmImage: ${{variables.vmImage}}
strategy:
runOnce:
deploy:
steps:
- task: PowerShell@2
name: outputPowershell
displayName: 'Generate variables'
inputs:
targetType: inline
pwsh: true
script: |
Write-Host "##vso[task.setvariable variable=varA;isOutput=true]valueA"
Write-Host "##vso[task.setvariable variable=varB;isOutput=true]valueB"
- deployment: JobB
environment: $(env)
dependsOn: JobA
pool:
vmImage: ${{variables.vmImage}}
variables:
varA: $[ dependencies.JobA.outputs['JobA.outputPowershell.varA'] ]
varB: $[ dependencies.JobA.outputs['JobA.outputPowershell.varB'] ]
strategy:
runOnce:
deploy:
steps:
- task: PowerShell@2
displayName: 'Dump variables'
inputs:
targetType: inline
pwsh: true
script: |
Write-Host "varA: $(varA)"
Write-Host "varB: $(varB)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment