简体   繁体   English

我正在尝试用另一个变量更新 azure devops 中的管道变量。 但我不确定如何做到这一点

[英]I'm trying to update a pipeline variable in azure devops with another variable. But I'm not sure how to do this exactly

I am reading a value from.json file and storing it in a variable.我正在从.json 文件中读取一个值并将其存储在一个变量中。 Then updating this value to the pipeline variable.然后将此值更新为管道变量。

$data = (Get-content -Path("C:/Desktop/file.json")).androidVersionName |Out-String

In the above cmd, I'm reading the data of androidVersionName from file.son and converting it to string data type在上面的 cmd 中,我从 file.son 中读取 androidVersionName 的数据并将其转换为字符串数据类型

Write-Host "##vso[task.setVariable variable=version;]$data"

In the above cmd, I'm setting the value of pipeline variable version to the value available in data.在上面的 cmd 中,我将管道变量版本的值设置为数据中可用的值。 But the value is not getting updated in powershell task of azure.但是该值在 azure 的 powershell 任务中没有得到更新。 Pls some one help.请帮忙。 I'm trying this for release pipeline CD我正在尝试将其用于发布管道 CD

Tried different methods suggested in comments section.尝试了评论部分建议的不同方法。 Not sure why it is not getting updated in the pipeline variable section.不知道为什么它没有在管道变量部分更新。 Will there be any problem related to access?访问会有什么问题吗? Or will it work if I add variable groups and use that?或者如果我添加变量组并使用它会起作用吗?

Can you check this line?你能检查一下这条线吗?

Write-Host "##vso[task.setVariable.variable=version;]data"

According to the documentation, you should use task.setVariable variable=version instead of task.setVariable.variable=version : Set variables in scripts根据文档,您应该使用task.setVariable variable=version而不是task.setVariable.variable=version在脚本中设置变量

Examples:例子:

Write-Host "##vso[task.setvariable variable=sauce]crushed tomatoes"
Write-Host "##vso[task.setvariable variable=secret.Sauce;issecret=true]crushed tomatoes with garlic"
Write-Host "##vso[task.setvariable variable=myOutputVar;isOutput=true]this is the value"

Additionally, check your Get-Content , you should convert your json string..... as example此外,检查您的Get-Content ,您应该转换您的 json 字符串.....例如

$data = Get-content -Path("C:/Desktop/file.json")| ConvertFrom-Json
$version = $data.androidVersionName

Write-Host "##vso[task.setVariable variable=version]$version"

echo "##vso[task.setvariable variable=myvar]Get-content -Path("C:/Desktop/file.json").androidVersionName |Out-String" --> tried this code and it worked like a charm echo "##vso[task.setvariable variable=myvar]Get-content -Path("C:/Desktop/file.json").androidVersionName |Out-String" --> 尝试了这段代码,它就像一个魅力

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure DevOps:在经典模式下使用 Release Pipeline 时,我无法将变量的值传递给其他任务 - Azure DevOps : while using Release Pipeline in classic mode, I'm not able to pass the value of a variable to other tasks 如何通过 Azure DevOps 发布管道中的 Azure Powershell 更新暂存槽的 IP 白名单? - How do I update the IP whitelist for a staging slot via Azure Powershell from an Azure DevOps Release Pipeline? 如何通过内联 PowerShell 命令设置 Azure Devops 管道变量? - How can I set an Azure Devops pipeline variable via an inline PowerShell command? 将 Azure Powershell 变量分配给 DevOps 管道变量 - Assign Azure Powershell variable to DevOps Pipeline variable 如何通过 PowerShell 脚本正确设置变量,然后使用 Azure DevOps 在另一个脚本中使用它? - How can I properly set a variable through a PowerShell script and then consume it in another using Azure DevOps? 如何在 Azure DevOps yaml 管道的每个循环中使用变量 - How to use a variable in each loop in Azure DevOps yaml pipeline Azure Devops 管道 - 如何将变量传递到 Powershell function - Azure Devops Pipeline - How to pass variable into Powershell function 如何在 Azure Devops 发布管道中使用 PowerShell 设置环境变量? - How to set an environment variable with PowerShell in Azure Devops release pipeline? 如何在Powershell中的变量中更新变量? - How do I update a variable in a variable in powershell? 在 Azure Devops 管道中设置变量的问题 - Issue with setting variable in Azure Devops pipeline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM