How to make Delay task take value from variable instead of hardcoded value for delayForMinutes input?
When i do following, it works fine:
- job: WaitForDeploy
dependsOn: Main
pool: Server
steps:
- task: Delay@1
inputs:
delayForMinutes: '1'
but when i do it like this it does not:
- job: WaitForDeploy
dependsOn: Main
pool: Server
steps:
- task: Delay@1
inputs:
delayForMinutes: '$(SleepCount)'
$(SleepCount) is defined in variables as empty string and later on is passed from python script to pipeline via:
print(f'##vso[task.setvariable variable=SleepCount]{delay_seconds}')
I am printing this out in previos job and it shows intiger correctly:
- script: 'echo $(SleepCount)'
displayName: "print_sleep_count"
it looks like this variable value is not passed beyond job where i return it from python script, how to pass it?
This do not work:
variables:
SleepCount: ""
jobs:
- job: Main
pool:
name: 'CDaaSLinux'
[...]
- task: PythonScript@0
inputs:
scriptSource: 'filePath'
scriptPath: '$(Build.SourcesDirectory)/sleep_count.py'
env:
ACTUAL_START_DATE: $(ActualStartDate_value)
- script: 'echo $(SleepCount)'
name: setVariable
displayName: "print_sleep_count"
- script: 'echo "Waiting for Deploy for $(SleepCount) minutes"'
displayName: "Deploy_message_for_user"
- job: WaitForDeploy
dependsOn: Main
variables:
SleepCount: $[ dependencies.Main.outputs['setVariable.SleepCount']]
pool: Server
steps:
- task: Delay@1
inputs:
delayForMinutes: '$(SleepCount)'
CodePudding user response:
In order to use a variable in a different stage/job you need to set the isoutput flag when setting the variable
print(f'##vso[task.setvariable variable=SleepCount;isoutput=true]{delay_seconds}')