问题描述
我想从 Build.Sourcebranch
设置 VersionSuffix
,但这失败了,因为 SourceBranch
包含 refs/heads/< branchname>
.
I want to set VersionSuffix
from Build.Sourcebranch
but this fails since SourceBranch
contains refs/heads/<branchname>
.
- task: DotNetCoreCLI@2
condition: succeeded()
inputs:
command: 'pack'
versioningScheme: ByPrereleaseNumber
majorVersion: '0'
minorVersion: '1'
patchVersion: '1'
packTimezone: 'utc'
buildProperties: VersionSuffix=$(Build.SourceBranch)-$(Build.BuildNumber)
我只想向 $(Build.SourceBranch)
添加 .Replace('/','_')
和一些类似的语句,但是我可以不能在表达式语法中找到有关该操作的任何信息.
I just want to add .Replace('/','_')
and a few similar statements to $(Build.SourceBranch)
, but I can't find anything in the expression syntax on how to do that.
发送另一个字符串(即 VersionSuffixRaw
)并在.csproj内使用 String.Replace
创建 VersionSuffix
无效.;由于某种原因,它只是被忽略了.
It didn't work to send in another string (i.e. VersionSuffixRaw
) and create the VersionSuffix
with String.Replace
inside the .csproj; it just got ignored for some reason.
注意:存在 Build.SourceBranchName
,该名称具有分支名称的最后一部分,因此,如果 SourceBranch
是 refs/heads/feature/foo
, SourceBranchName
将是 foo
.但是,由于版本字符串中的_无效,因此分支命名 feature/JIRA-123_foo_unittest
无效.
Note: There is Build.SourceBranchName
which has the last part of a branchname, so if SourceBranch
is refs/heads/feature/foo
, SourceBranchName
will be foo
. However a branch namd feature/JIRA-123_foo_unittest
will not work since _ is not valid in a version string.
推荐答案
对于其他通过搜索找到此内容的人,现在有一个替换表达式: MS Doc
For others finding this through searches, there is now a replace expression: MS Doc
大致像这样用下划线代替下划线:
Roughly like this to replace underscores with hypens:
variables:
suffix: $[replace(variables['build.sourcebranchname'], '_', '-')]
这篇关于如何替换azure-pipelines.yaml中的可变字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!