[英]Azure pipeline set displayname of task based on condition
In the build pipeline I have a job with a powershell script setting the applicatiuon name based on a variable like this:在构建管道中,我有一个 powershell 脚本的工作基于这样的变量设置应用程序名称:
$applicationName = If ('$(configuration)' -eq 'Release') { 'Appname' } Else { 'Appname-Test' }
Write-Host "##vso[task.setvariable variable=applicationName]$applicationName"
I try to set the display name of the PublishBuildArtifacts@1
variable to the variable like this:我尝试将
PublishBuildArtifacts@1
变量的显示名称设置为这样的变量:
- task: PublishBuildArtifacts@1
displayName: $[variables.applicationName] # runtime variable
But this literally displays $[variables.applicationName]
instead of the variable value.但这实际上显示
$[variables.applicationName]
而不是变量值。 How can I change the displayname of a task based on a variable?如何根据变量更改任务的显示名称?
You can just use the variable in this way: $(variableName).您可以通过这种方式使用变量:$(variableName)。 for example:
例如:
pool:
vmImage: 'windows-latest'
variables:
test: "SomeValue"
steps:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: 'Write-Host "Hello World"'
displayName: "The variable $(test)"
The result is:结果是:
It doesn't appear that this is currently possible.目前看来这是不可能的。 In both issues I found, they described this as a feature request.
在我发现的两个问题中,他们都将其描述为功能请求。
https://github.com/MicrosoftDocs/azure-devops-docs/issues/2327 https://github.com/MicrosoftDocs/azure-devops-docs/issues/2327
https://github.com/microsoft/azure-pipelines-yaml/issues/45 https://github.com/microsoft/azure-pipelines-yaml/issues/45
I assume ${{..}}
is the way to go. You know the configuration
at compile time, so you can create the app name at compile time.我假设
${{..}}
是通往 go 的路径。您知道编译时的configuration
,因此您可以在编译时创建应用程序名称。
variables:
${{ if eq(variables.configuration, 'Release') }}:
applicationName: 'Appname'
${{ if ne(variables.configuration, 'Release') }}:
applicationName: 'Appname-Test'
- task: PublishBuildArtifacts@1
displayName: ${{ variables.applicationName }}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.