Reputation: 310
How do I get my environment variable from my first stage to my second stage?
Issue -> I get an empty "" value from my echo result.
azure-pipeline.yml
trigger:
branches:
include:
- main
paths:
include:
- infra/*
- .pipelines/*
variables:
vmImageName: 'ubuntu-latest'
root: $(System.DefaultWorkingDirectory)
stages:
- stage: TakePITR
dependsOn: []
variables:
env: poc
jobs:
- job: GetPitrTime
steps:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
$iso8601_time = Get-Date -Format "o"
echo "##vso[task.setvariable variable=pitr_time;isOutput=True]$iso8601_time"
name: PitrVar
displayName: "Get point-in-time before second stage"
- stage: TestOutputEnvVar
dependsOn: TakePITR
variables:
env: poc
PITR: $[ stageDependencies.TakePITR.GetPitrTime.outputs['PitrVar.pitr_time']]
jobs:
- job:
steps:
- script: |
echo $pitr_time
echo $PITR
displayName: 'echo value'
I don't understand what I'm doing wrong here.
This is the result of my pipeline:
Upvotes: 0
Views: 644
Reputation: 40769
You have indendation issue:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
$iso8601_time = Get-Date -Format "o"
echo "##vso[task.setvariable variable=pitr_time;isOutput=true]$iso8601_time"
name: PitrVar
displayName: "Get point-in-time before second stage"
Name and displayName should be on the same level as input and then:
Full code is here
trigger:
branches:
include:
- main
paths:
include:
- infra/*
- .pipelines/*
variables:
vmImageName: 'ubuntu-latest'
root: $(System.DefaultWorkingDirectory)
stages:
- stage: TakePITR
dependsOn: []
variables:
env: poc
jobs:
- job: GetPitrTime
steps:
- task: PowerShell@2
name: PitrVar
displayName: "Get point-in-time before second stage"
inputs:
targetType: 'inline'
script: |
$iso8601_time = Get-Date -Format "o"
echo "##vso[task.setvariable variable=pitr_time;isOutput=true]$iso8601_time"
- stage: TestOutputEnvVar
dependsOn: TakePITR
variables:
env: poc
PITR: $[ stageDependencies.TakePITR.GetPitrTime.outputs['PitrVar.pitr_time']]
jobs:
- job:
steps:
- script: |
echo $pitr_time
echo $PITR
displayName: 'echo value'
Upvotes: 2