I have a Powershell script which returns a string value. I'm invoking this script using a AzurePowerShell task and I want to retain the returned value to use it in my subsequent tasks within the same pipeline. How can I do that? Any ideas, please?
function a {
<<processing steps>>
return $(testString)
}
- task: AzurePowerShell@
ScriptPath: Powershelltest.ps1 (calls the above powershell script)
- task: AzureCLI@
inlineScript: |
use the value from $testString(??)
How can I catch the return value from Powershell in the first task (AzurePowerShell) and use it in AzureCLI task?
Thanks
[1]: https://i.stack.imgur.com/Ktlaf.png
CodePudding user response:
Use this command: ##vso[task.setvariable variable=testString]$testString'
in your first task. In your second task you will call the variable like this: $(testString).
Your function should look like the following:
function a {
<<processing steps>>
##vso[task.setvariable variable=testString]$testString'
}
You don't necessarily need to return the value if only want to use it in a following step.