powershell” ## vso [task.setVariable variable = testvar1]在管道中不起作用
在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键有关吗?
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?
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论