I have set environment variable in azure yaml pipeline like this
- task: PowerShell@2
inputs:
targetType: 'inline'
script: | $env:MY_VARIABLE = "$(my-value)"
$env:MY_VARIABLE >> test.txt
...
when I run the pipeline and go to published artifact in summary section of the pipeline, I can see that test.txt has correct value. Is there a way I can read this MY_VARIABLE
in c# code, which is going to be run with a specflow task in this yaml pipeline
You can't read Azure Pipelines variable directly in C#. However, each Azure Pipeline variable is mapped to an environment variable (except for secrets). You can read about this here .
So, all that you need is Environment.GetEnvironmentVariable
.
And of course you need to run your code on pipeline, not compile create package and then run somewhere else.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.