Add a condition to run Gitversion when branch is main.

huangapple go评论69阅读模式
英文:

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'))

huangapple
  • 本文由 发表于 2023年2月27日 18:49:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75579491.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定