powershell” ## vso [task.setVariable variable = testvar1]在管道中不起作用

发布于 2025-02-13 21:03:30 字数 956 浏览 3 评论 0原文

在DevOps Pipeline中,使用YAML文件中的PowerShell脚本来读取JSON参数文件并将这些值推入YAML变量。

我可以成功读取和提取参数,

ScriptType: InlineScript
Inline: |
$params = Get-Content main.parameters.json -Raw | ConvertFrom-Json 
$clientname = Out-String -InputObject $params.parameters.clientname
$clientname = $clientname.ToLower() 

但是当我尝试使用它设置变量时,

Write-Host "##vso[task.setvariable variable=testvar2]$clientname" 

不会将testVar2设置为$ clientname值 - 但是,如果我将字符串值明确分配给变量$ clientname ='Pickles' - 这确实更新变量。 $ clientName类型以字符串返回。与返回JSON键有关吗?

完整代码img

输出img

edit : 我可以绝对可以阅读JSON- $ clientname的填充有正确的值 - 问题是我尝试使用task.setvariable将其分配给YAML变量时。如果您查看完整代码,则$ newclientname按预期工作,例如填充YAML变量 - $ clientname却没有。

In a devops pipeline Im using a powershell script in a YAML file to read a json parameter file and push these values into YAML variables.

I can successfully read and extract the parameters

ScriptType: InlineScript
Inline: |
$params = Get-Content main.parameters.json -Raw | ConvertFrom-Json 
$clientname = Out-String -InputObject $params.parameters.clientname
$clientname = $clientname.ToLower() 

but when i try to set the variables using

Write-Host "##vso[task.setvariable variable=testvar2]$clientname" 

it does not set the testvar2 to the $clientname value - however if i explicitly assign a string value to the variable $clientname = 'pickles' - this does update the variable.
The $clientname type returns as a string. Is there something to do with how the json keys are returned?

full code img

output img

EDIT:
I can read the json absolutely fine - $clientname is populated with the correct value - the issue is when i try to assign it to a YAML variable using task.setvariable. If you look at the full code the $newclientname works as expected e.g populates the yAML variable - $clientname does not.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文