azure-devops - Azure 开发运营 : Getting variable value by concatenating other variables'value as task input

标签 azure-devops azure-pipelines azure-pipelines-release-pipeline

我的发布管道变量选项卡设置如下:

Environment variables

我想通过连接initialVariable的结果来访问任务显示名称中的my123变量。

Outputs

到目前为止,我已尝试仅引用initialVariable,它在作业的显示名称中返回了正确的值。

enter image description here

但是当我尝试使用initialVariable(= 123)创建my123值时,我没有获得正确的值(希望$(initialVariable)将转换为123并且$(my123)将获得正确的“finalValue”)。

enter image description here

最佳答案

Azure DevOps: Getting variable value by concatenating other variables'value as task input

这是一个已知问题。因为构建/发布管道尚不支持嵌套变量的值(例如 $(my$(initialVariable)))

检查my other thread了解一些详细信息。

解决方法是添加一个 Run Inline Powershell 任务来根据输入管道变量设置变量,就像 Josh 回答的那样。

对于您的情况,我通过以下 Powershell 脚本对其进行测试:

 if ($(initialVariable)-eq "123")
 {
   Write-Host "##vso[task.setvariable variable=my123]finalvalue"
 }
 else
 {
   Write-Host "##vso[task.setvariable variable=my123]otherValue"
 }

然后我们可以在下面的任务中根据变量initialVariable的值获取变量my123,我添加命令行任务来显示该值:

enter image description here

结果中,命令行任务中的值是正确的finalvalue。但显示名称仍然是 $(my123):

enter image description here

重要:

这也是您评论中的问题。此行为是预期的。因为显示名称中的变量只是为了获取预定义值。这是静态获取,而不是动态获取。变量 my123 在运行 powershell 时被分配。显示名称中的静态变量my123不会进入powershell代码运行的环境。

所以,标题中的变量my123无法获取任务powershell中的值。但其他任务可以很好地使用它。

希望这个答案能解决你的困惑。

关于azure-devops - Azure 开发运营 : Getting variable value by concatenating other variables'value as task input,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57481921/

相关文章:

protractor - 运行 Protractor 测试时更改VSTS代理 session 屏幕分辨率

Azure Kubernetes 服务 : Image Pull Error (Authentication) even though ImagePullSecret was added in CD pipeline

azure-devops - 在 PowerShell 任务中执行 az login

azure - 如何仅从一个 .sln 中的多个项目中发布更改项目?

Azure Pipeline 将 DacPac 部署到 Azure SQL - 如何添加防火墙规则?

azure - 如何在azure Release管道中使用Linux代理运行vstest?

Azure Devops 由于权限无法以编程方式创建服务 Hook

entity-framework - 使用 Azure Pipeline 任务进行 EF 迁移

azure-devops - 如何在可从单元测试访问的 Azure DevOps 服务中传递/存储 secret

azure-devops - 尝试使用 azure-pipelines.yml 将管道池设置为默认代理池时出错