英文:
Add a condition to run Gitversion when branch is main
问题
以下是您要翻译的内容:
We are using a Azure yaml pipeline and Gitversion, configured to version up based on PR templates.
- task: gitversion/execute@0
inputs:
useConfigFile: true
configFilePath: 'GitVersion.yml'
- script: echo current version is $(GitVersion.MajorMinorPatch)
displayName: 'Dispaly calculated version'
- task: PowerShell@2
inputs:
targetType: 'inline'
script: 'echo \##vso[build.updatebuildnumber]$(GitVersion.MajorMinorPatch)'
How do i set a condition to run only on main branch. I have a same setup of pipelines configured in feature branch for different testing. So when Gitversion should execute only when main branch is being used.
Gitversion.yaml:
mode: Mainline
branches:
feature:
regex: ^feature?[/-]
tag: feat-{BranchName}
source-branches: ['main','master']
fix:
regex: bugfix(es)?[/-]
tag: bugfix-{BranchName}
source-branches: ['main','master']
ignore:
sha: []
merge-message-formats: {}
请注意,代码部分已被忽略,只返回翻译的文本部分。
英文:
We are using a Azure yaml pipeline and Gitversion, configured to version up based on PR templates.
- task: gitversion/execute@0
inputs:
useConfigFile: true
configFilePath: 'GitVersion.yml'
- script: echo current version is $(GitVersion.MajorMinorPatch)
displayName: 'Dispaly calculated version'
- task: PowerShell@2
inputs:
targetType: 'inline'
script: 'echo \##vso[build.updatebuildnumber]$(GitVersion.MajorMinorPatch)'
How do i set a condition to run only on main branch. I have a same setup of pipelines configured in feature branch for different testing. So when Gitversion should execute only when main branch is being used.
Gitversion.yaml:
mode: Mainline
branches:
feature:
regex: ^feature?[/-]
tag: feat-{BranchName}
source-branches: ['main','master']
fix:
regex: bugfix(es)?[/-]
tag: bugfix-{BranchName}
source-branches: ['main','master']
ignore:
sha: []
merge-message-formats: {}
答案1
得分: 0
这个条件帮助我实现我的需求:
and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
英文:
This condition helps me to acheive my requriement
and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论