azure-devops - 为什么这些 Azure DevOps 预定义变量在管道构建中不起作用?
问题描述
鉴于以下 yml 片段,此脚本中使用的 Azure DevOps Pipeline预定义变量不会被“拾取”。
pool:
vmImage: 'Ubuntu 16.04'
variables:
buildConfiguration: 'Release'
trigger:
branches:
include:
- master
paths:
include:
<snipped>
pr:
autoCancel: false
paths:
include:
<snipped>
steps:
# Remove this task once .NET Core 2.2 is added to hosted agent.
- task: DotNetCoreInstaller@0
inputs:
packageType: 'sdk'
version: '2.2.100'
- script: dotnet build --configuration $(buildConfiguration) -p:Version=$(Year:yyyy).$(Month).$(DayOfMonth).$(Rev:r)
displayName: 'dotnet build'
workingDirectory: 'src/<snipped>'
请注意我如何尝试设置 a 的 version 属性dotnet build
:
dotnet build --configuration $(buildConfiguration) -p:Version=$(Year:yyyy).$(Month).$(DayOfMonth).$(Rev:r)
但!当我手动定义构建名称..然后引用该变量..它有效!
name: $(Year:yyyy).$(Month).$(DayOfMonth).$(Rev:r)
<snipped>
- script: dotnet build --configuration $(buildConfiguration) -p:Version=$(Build.BuildNumber)
displayName: 'dotnet build'
workingDirectory: 'src/<snipped>'
这是 Azure DevOps 的错误吗?
解决方案
这些变量$(Year:yyyy)
$(Month)
$(DayOfMonth)
$(Rev:r)
不是常规预定义构建变量的一部分,如您所见,它们在此处的列表中不存在。
您只能以内部版本号格式(name
在 YAML 中)使用这些变量。
因此,正如您所做的那样,您可以在那里使用它们,并在构建期间使用变量Build.BuildNumber
来获取值。
推荐阅读
- html - 占位符在 Chrome 和 Safari 中不起作用,但在 Firefox 中起作用
- amazon-web-services - 如何在 Redshift 中查看节点编号历史记录
- sql - 具有多个表的备份数据库powershell
- cypress - Hydra 是否支持 cypress-plugin-snapshots 插件
- c++ - C++ 在具有 unique_ptr 的向量中没有重载函数错误的实例
- r - R:如何将多个 txt.gz 文件读入 R 中的单个表中
- r - 如何将数据(即特定列)从 csv 文件插入 ggpplot 以获得所述图像?
- android - 快速字符串中的 AES256 加密不匹配
- flutter - 配置项目“:flutter_launch”时出现问题
- android - 如何为android app自定义jitsi meet视频会议的高度和宽度