英文:
Azure DevOps Pipeline branch name matching
问题
我有一个Azure DevOps Pipeline,其中包含以下的YAML片段。
我只想在与版本A.B.C或可选的子版本匹配的开发分支上触发构建(但仅包含数字和点,不包含任何字母字符)。
示例:
- myproject/v3.5.2_dev
- myproject/v3.5.2.1_dev
- myproject/v4.9.7.1.2_dev
以下的Pipeline YAML文件在我推送更改时似乎不会自动触发。匹配有什么问题吗?
我可以在分支包括筛选器中使用扩展的模式匹配吗?
trigger:
batch: true
branches:
include:
# - myproject/*
# 仅在`myproject/vX.Y.Z_dev`分支上触发(可选的vA.B.C.D...也可以)
- myproject/v+([0-9]).+([0-9]).+([0-9])*([0-9.])_dev
paths:
exclude:
- '**/*.md'
英文:
I have an Azure DevOps Pipeline with the following yaml snippet.
I want to only trigger a build on development branches with branch names that match versions A.B.C or optional sub-versions (but only with numbers and dots, not with any alpha characters).
Examples:
- myproject/v3.5.2_dev
- myproject/v3.5.2.1_dev
- myproject/v4.9.7.1.2_dev
The following pipepline yaml file does not seem to automatically trigger when I push changes. Is there something wrong with the mathcing?
Can I use extended globbing in the branch include filter?
trigger:
batch: true
branches:
include:
# - myproject/*
# only trigger for `myproject/vX.Y.Z_dev` branches (optionally vA.B.C.D... too)
- myproject/v+([0-9]).+([0-9]).+([0-9])*([0-9.])_dev
paths:
exclude:
- '**/*.md'
答案1
得分: 1
这是我最终得到的 - 通过bash脚本设置变量并在我的任务中检查条件。
variables:
IS_RELEASE_BRANCH: false
steps:
#! 如果分支名与正则表达式匹配,则设置IS_RELEASE_BRANCH为true
- bash: |
echo "Checking SourceBranch: $(Build.SourceBranch)"
echo "$(Build.SourceBranch)" | grep -E 'ind-efd/v[[:digit:].]+_dev'
if (( $? == 0 )) ; then
echo "##vso[task.setvariable variable=IS_RELEASE_BRANCH]true"
echo "IS_RELEASE_BRANCH: true"
else
echo "IS_RELEASE_BRANCH: false"
fi
- task: Foo@1
displayName: Bar
condition: and(succeeded(), eq(variables.IS_RELEASE_BRANCH, 'true'))
英文:
This is what I ended up with - setting a variable via a bash script and checking the condition in my task.
variables:
IS_RELEASE_BRANCH: false
steps:
#! set IS_RELEASE_BRANCH if branch name matches the regular expression"
- bash: |
echo "Checking SourceBranch: $(Build.SourceBranch)"
echo "$(Build.SourceBranch)" | grep -E 'ind-efd/v[[:digit:].]+_dev'
if (( $? == 0 )) ; then
echo "##vso[task.setvariable variable=IS_RELEASE_BRANCH]true"
echo "IS_RELEASE_BRANCH: true"
else
echo "IS_RELEASE_BRANCH: false"
fi
- task: Foo@1
displayName: Bar
condition: and(succeeded(), eq(variables.IS_RELEASE_BRANCH, 'true'))
答案2
得分: 0
如在这个SO帖子中提到的,截止目前,Azure DevOps不支持分支筛选中的正则表达式。作为替代,您可以使用条件表达式,如startsWith
和endsWith
,来在job
或step
级别进行评估。
GitHub问题链接:https://github.com/microsoft/azure-pipelines-yaml/issues/149
英文:
As mentioned in this SO thread, regular expression in branch filters are not supported in Azure DevOps as of now. Alternatively you can use conditions with expressions like startsWith
and endsWith
to evaluate on job
or step
level
GitHub issue: https://github.com/microsoft/azure-pipelines-yaml/issues/149
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论